Sourcestd/logger/core.d
isLoggingEnabled()(LogLevelll, LogLevelloggerLL, LogLevelglobalLL, lazy boolcondition = true);log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy Aargs)args.length != 1);log(T, string moduleName = __MODULE__)(const LogLevelll, lazy boolcondition, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);LogLevelll | TheLogLevel used by this log call. |
boolcondition | The condition must betrue for the data to be logged. |
Aargs | The data that should be logged. |
Example
log(LogLevel.warning,true,"Hello World", 3.1415);
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy Aargs)args.length > 1 && !is(Unqual!(A[0]) : bool));log(T, string moduleName = __MODULE__)(const LogLevelll, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);LogLevelll | TheLogLevel used by this log call. |
Aargs | The data that should be logged. |
Example
log(LogLevel.warning,"Hello World", 3.1415);
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs)args.length != 1);log(T, string moduleName = __MODULE__)(lazy boolcondition, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);boolcondition | The condition must betrue for the data to be logged. |
Aargs | The data that should be logged. |
Example
log(true,"Hello World", 3.1415);
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(Unqual!(A[0]) == LogLevel) ||args.length == 0);Aargs | The data that should be logged. |
Example
log("Hello World", 3.1415);
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy stringmsg, lazy Aargs);LogLevelll | TheLogLevel used by this log call. |
boolcondition | The condition must betrue for the data to be logged. |
stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
logf(LogLevel.warning,true,"Hello World %f", 3.1415);
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy stringmsg, lazy Aargs);LogLevelll | TheLogLevel used by this log call. |
stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
logf(LogLevel.warning,"Hello World %f", 3.1415);
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);boolcondition | The condition must betrue for the data to be logged. |
stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
logf(true,"Hello World %f", 3.1415);
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
logf("Hello World %f", 3.1415);
defaultLogFunction(LogLevel ll)trace = defaultLogFunction!(LogLevel.trace).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);info = defaultLogFunction!(LogLevel.info).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);warning = defaultLogFunction!(LogLevel.warning).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);error = defaultLogFunction!(LogLevel.error).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);critical = defaultLogFunction!(LogLevel.critical).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);fatal = defaultLogFunction!(LogLevel.fatal).defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length > 0 && !is(Unqual!(A[0]) : bool) || args.length == 0);| bool condition | The condition must betrue for the data to be logged. |
| A args | The data that should be logged. |
Example
trace(1337,"is number");info(1337,"is number");error(1337,"is number");critical(1337,"is number");fatal(1337,"is number");trace(true, 1337,"is number");info(false, 1337,"is number");error(true, 1337,"is number");critical(false, 1337,"is number");fatal(true, 1337,"is number");
defaultLogFunctionf(LogLevel ll)tracef = defaultLogFunctionf!(LogLevel.trace).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);infof = defaultLogFunctionf!(LogLevel.info).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);warningf = defaultLogFunctionf!(LogLevel.warning).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);errorf = defaultLogFunctionf!(LogLevel.error).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);criticalf = defaultLogFunctionf!(LogLevel.critical).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);fatalf = defaultLogFunctionf!(LogLevel.fatal).defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);| string msg | Theprintf-style string. |
| A args | The data that should be logged. |
Example
tracef("is number %d", 1);infof("is number %d", 2);errorf("is number %d", 3);criticalf("is number %d", 4);fatalf("is number %d", 5);The second version of the function logs data to thesharedLog in aprintf-style manner.In order for the resulting log message to be logged theLogLevel mustbe greater or equal than theLogLevel of thesharedLog andmust be greater or equal than the globalLogLevel.Additionally theLogLevel must be greater or equal than theLogLevelof thestdSharedLogger.
| bool condition | The condition must betrue for the data to be logged. |
| string msg | Theprintf-style string. |
| A args | The data that should be logged. |
Example
tracef(false,"is number %d", 1);infof(false,"is number %d", 2);errorf(true,"is number %d", 3);criticalf(true,"is number %d", 4);fatalf(someFunct(),"is number %d", 5);
LogLevel: ubyte;LogLevel.fatal is called the shutdown handler ofthat logger is called.alltraceinfowarningerrorcriticalfataloffLogger;LogEntry;file;line;funcName;prettyFuncName;moduleName;logLevel;threadId;timestamp;msg;logger;lv);LogLevellv | LogLevel to use for thisLogger instance. |
writeLogMsg(ref LogEntrypayload);LogEntrypayload | All information associated with call to log function. |
logMsgPart(scope const(char)[]msg);finishLogMsg();logLevel() const;logLevel(const LogLevellv);Example
auto f =new FileLogger(stdout);f.logLevel = LogLevel.info;assert(f.logLevel == LogLevel.info);
fatalHandler();fatalHandler(void delegate() @safefh);forwardMsg(ref LogEntrypayload);forwardMsg will ensure proper synchronization and then callwriteLogMsg. This is an API for implementing your own loggers and should not be called by normal user code. A notable difference from other logging functions is that theglobalLogLevel wont be evaluated again since it is assumed that the caller already checked that.memLogFunctions(LogLevel ll)trace = .Logger.memLogFunctions!(LogLevel.trace).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));tracef = .Logger.memLogFunctions!(LogLevel.trace).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);info = .Logger.memLogFunctions!(LogLevel.info).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));infof = .Logger.memLogFunctions!(LogLevel.info).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);warning = .Logger.memLogFunctions!(LogLevel.warning).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));warningf = .Logger.memLogFunctions!(LogLevel.warning).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);error = .Logger.memLogFunctions!(LogLevel.error).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));errorf = .Logger.memLogFunctions!(LogLevel.error).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);critical = .Logger.memLogFunctions!(LogLevel.critical).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));criticalf = .Logger.memLogFunctions!(LogLevel.critical).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);fatal = .Logger.memLogFunctions!(LogLevel.fatal).logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if (args.length == 0 || args.length > 0 && !is(A[0] : bool));fatalf = .Logger.memLogFunctions!(LogLevel.fatal).logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, lazy A args);logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)args.length == 0 ||args.length > 0 && !is(A[0] : bool));Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.trace(1337,"is number");s.info(1337,"is number");s.error(1337,"is number");s.critical(1337,"is number");s.fatal(1337,"is number");
logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs);boolcondition | The condition must betrue for the data to be logged. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.trace(true, 1337,"is number");s.info(false, 1337,"is number");s.error(true, 1337,"is number");s.critical(false, 1337,"is number");s.fatal(true, 1337,"is number");
logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);boolcondition | The condition must betrue for the data to be logged. |
stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stderr);s.tracef(true,"is number %d", 1);s.infof(true,"is number %d", 2);s.errorf(false,"is number %d", 3);s.criticalf(someFunc(),"is number %d", 4);s.fatalf(true,"is number %d", 5);
logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);stringmsg | Theprintf-style string. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stderr);s.tracef("is number %d", 1);s.infof("is number %d", 2);s.errorf("is number %d", 3);s.criticalf("is number %d", 4);s.fatalf("is number %d", 5);
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy Aargs)args.length != 1);log(T, string moduleName = __MODULE__)(const LogLevelll, lazy boolcondition, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);Aargs | The data that should be logged. |
boolcondition | The condition must betrue for the data to be logged. |
Aargs | The data that is to be logged. |
Example
auto l =new StdioLogger();l.log(1337);
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy Aargs)args.length > 1 && !is(Unqual!(A[0]) : bool) ||args.length == 0);log(T)(const LogLevelll, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);LogLevelll | The specificLogLevel used for logging the log message. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.log(LogLevel.trace, 1337,"is number");s.log(LogLevel.info, 1337,"is number");s.log(LogLevel.warning, 1337,"is number");s.log(LogLevel.error, 1337,"is number");s.log(LogLevel.fatal, 1337,"is number");
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs)args.length != 1);log(T)(lazy boolcondition, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);boolcondition | The condition must betrue for the data to be logged. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.log(true, 1337,"is number");s.log(true, 1337,"is number");s.log(true, 1337,"is number");s.log(false, 1337,"is number");s.log(false, 1337,"is number");
log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(immutable(A[0]) == immutable(LogLevel)) ||args.length == 0);log(T)(lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.log(1337,"is number");s.log(info, 1337,"is number");s.log(1337,"is number");s.log(1337,"is number");s.log(1337,"is number");
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy stringmsg, lazy Aargs);LogLevelll | The specificLogLevel used for logging the log message. |
boolcondition | The condition must betrue for the data to be logged. |
stringmsg | The format string used for this log call. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.logf(LogLevel.trace,true ,"%d %s", 1337,"is number");s.logf(LogLevel.info,true ,"%d %s", 1337,"is number");s.logf(LogLevel.warning,true ,"%d %s", 1337,"is number");s.logf(LogLevel.error,false ,"%d %s", 1337,"is number");s.logf(LogLevel.fatal,true ,"%d %s", 1337,"is number");
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy stringmsg, lazy Aargs);LogLevelll | The specificLogLevel used for logging the log message. |
stringmsg | The format string used for this log call. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.logf(LogLevel.trace,"%d %s", 1337,"is number");s.logf(LogLevel.info,"%d %s", 1337,"is number");s.logf(LogLevel.warning,"%d %s", 1337,"is number");s.logf(LogLevel.error,"%d %s", 1337,"is number");s.logf(LogLevel.fatal,"%d %s", 1337,"is number");
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);boolcondition | The condition must betrue for the data to be logged. |
stringmsg | The format string used for this log call. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.logf(true ,"%d %s", 1337,"is number");s.logf(true ,"%d %s", 1337,"is number");s.logf(true ,"%d %s", 1337,"is number");s.logf(false ,"%d %s", 1337,"is number");s.logf(true ,"%d %s", 1337,"is number");
logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);stringmsg | The format string used for this log call. |
Aargs | The data that should be logged. |
Example
auto s =new FileLogger(stdout);s.logf("%d %s", 1337,"is number");s.logf("%d %s", 1337,"is number");s.logf("%d %s", 1337,"is number");s.logf("%d %s", 1337,"is number");s.logf("%d %s", 1337,"is number");
sharedLog();sharedLog(shared(Logger)logger);Example
sharedLog =newshared FileLogger(yourFile);The example sets a newFileLogger as new
sharedLog.If at some point you want to use the original default logger again, you canusesharedLog = null;. This will put back the original.NoteWhile getting and settingsharedLog is thread-safe, it has to be consideredthat the returned reference is only a current snapshot and in the followingcode, you must make sure no other thread reassigns to it between reading andwritingsharedLog.
sharedLog is only thread-safe if the usedLogger is thread-safe.The defaultLogger is thread-safe.if (sharedLog !is myLogger)sharedLog =newshared myLogger;
globalLogLevel();globalLogLevel(LogLevelll);StdForwardLogger:std.logger.core.Logger;StdForwardLogger will always forward anything to the sharedLog.StdForwardLogger will not throw if data is logged withLogLevel.fatal.auto nl1 =newStdForwardLogger(LogLevel.all);
lv = LogLevel.all);LogLevellv | TheLogLevel for theMultiLogger. By default the LogLevel isall. |
stdThreadLocalLog();stdThreadLocalLog(Loggerlogger);import std.logger.filelogger : FileLogger;import std.file : deleteme, remove;Logger l =stdThreadLocalLog;stdThreadLocalLog =new FileLogger(deleteme ~"-someFile.log");scope(exit) remove(deleteme ~"-someFile.log");auto tempLog =stdThreadLocalLog;stdThreadLocalLog = l;destroy(tempLog);