std.experimental.logger.core
- template isLoggingActiveAt(LogLevel ll)
-
This template evaluates if the passed
LogLevelis active. The previously described version statements are used to decide if theLogLevelis active. The version statements only influence the compile unit they are used with, therefore this function can only disable logging this specific compile unit. - enum bool isLoggingActive;
-
This compile-time flag is
trueif logging is not statically disabled. - @safe bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, LogLevel globalLL, lazy bool condition = true);
-
This functions is used at runtime to determine if a
LogLevelis active. The same previously defined version statements are used to disable certain levels. Again the version statements are associated with a compile unit and can therefore not disable logging in other compile units. pure bool isLoggingEnabled()(LogLevel ll) @safe nothrow @nogc - template moduleLogLevel(string moduleName) if (!moduleName.length)
template moduleLogLevel(string moduleName) if (moduleName.length) -
This template returns the
LogLevelnamed "logLevel" of typeLogLeveldefined in a user defined module where the filename has the suffix "loggerconfig.d". ThisLogLevelsets the minimalLogLevelof the module.A minimal
LogLevelcan be defined on a per module basis. In order to define a moduleLogLevela file with a modulename "MODULENAME_loggerconfig" must be found. If no such module exists and the module is a nested module, it is checked if there exists a "PARENT_MODULE_loggerconfig" module with such a symbol. If this module exists and it contains aLogLevelcalled logLevel thisLogLevelwill be used. This parent lookup is continued until there is no parent module. Then the moduleLogLevel isLogLevel.all.- Examples:
-
static assert(moduleLogLevel!"" == LogLevel.all);
- Examples:
-
static assert(moduleLogLevel!"not.amodule.path" == LogLevel.all);
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy bool condition, lazy A args)
Constraints: if (args.length != 1);
void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__); -
This function logs data.
In order for the data to be processed, the
LogLevelof the log call must be greater or equal to theLogLevelof thesharedLogand thedefaultLogLevel; additionally the condition passed must betrue.- Parameters:
LogLevel llThe LogLevelused by this log call.bool conditionThe condition must be truefor the data to be logged.A argsThe data that should be logged.
- Example
log(LogLevel.warning, true, "Hello World", 3.1415);
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
Constraints: if (args.length > 1 && !is(Unqual!(A[0]) : bool));
void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__); -
This function logs data.
In order for the data to be processed the
LogLevelof the log call must be greater or equal to theLogLevelof thesharedLog.- Parameters:
LogLevel llThe LogLevelused by this log call.A argsThe data that should be logged.
- Example
log(LogLevel.warning, "Hello World", 3.1415);
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
Constraints: if (args.length != 1);
void log(T, string moduleName = __MODULE__)(lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__); -
This function logs data.
In order for the data to be processed the
LogLevelof thesharedLogmust be greater or equal to thedefaultLogLeveladd the condition passed must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.A argsThe data that should be logged.
- Example
log(true, "Hello World", 3.1415);
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args)
Constraints: if (args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(Unqual!(A[0]) == LogLevel) || args.length == 0); -
This function logs data.
In order for the data to be processed the
LogLevelof thesharedLogmust be greater or equal to thedefaultLogLevel.- Parameters:
A argsThe data that should be logged.
- Example
log("Hello World", 3.1415); - void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy bool condition, lazy string msg, lazy A args);
-
This function logs data in a
printf-style manner.In order for the data to be processed the
LogLevelof the log call must be greater or equal to theLogLevelof thesharedLogand thedefaultLogLeveladditionally the condition passed must betrue.- Parameters:
LogLevel llThe LogLevelused by this log call.bool conditionThe condition must be truefor the data to be logged.string msgThe printf-style string.A argsThe data that should be logged.
- Example
logf(LogLevel.warning, true, "Hello World %f", 3.1415);
- void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy string msg, lazy A args);
-
This function logs data in a
printf-style manner.In order for the data to be processed the
LogLevelof the log call must be greater or equal to theLogLevelof thesharedLogand thedefaultLogLevel.- Parameters:
LogLevel llThe LogLevelused by this log call.string msgThe printf-style string.A argsThe data that should be logged.
- Example
logf(LogLevel.warning, "Hello World %f", 3.1415);
- void logf(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);
-
This function logs data in a
printf-style manner.In order for the data to be processed the
LogLevelof the log call must be greater or equal to thedefaultLogLeveladditionally the condition passed must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.string msgThe printf-style string.A argsThe data that should be logged.
- Example
logf(true, "Hello World %f", 3.1415);
- void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);
-
This function logs data in a
printf-style manner.In order for the data to be processed the
LogLevelof the log call must be greater or equal to thedefaultLogLevel.- Parameters:
string msgThe printf-style string.A argsThe data that should be logged.
- Example
logf("Hello World %f", 3.1415); - template defaultLogFunction(LogLevel ll)
-
This template provides the global log functions with the
LogLevelis encoded in the function name.The aliases following this template create the public names of these log functions.
- alias 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);
alias 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);
alias 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);
alias 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);
alias 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);
alias 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); -
This function logs data to the
stdThreadLocalLog, optionally depending on a condition.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof thestdThreadLocalLogand must be greater or equal than the globalLogLevel. Additionally theLogLevelmust be greater or equal than theLogLevelof thestdSharedLogger. If a condition is given, it must evaluate totrue.- Parameters:
bool condition The condition must be truefor 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");
- template defaultLogFunctionf(LogLevel ll)
-
This template provides the global
printf-style log functions with theLogLevelis encoded in the function name.The aliases following this template create the public names of the log functions.
- alias 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);
alias 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);
alias 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);
alias 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);
alias 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);
alias 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); -
This function logs data to the
sharedLogin aprintf-style manner.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof thesharedLogand must be greater or equal than the globalLogLevel. Additionally theLogLevelmust be greater or equal than theLogLevelof thestdSharedLogger.- Parameters:
string msg The printf-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 thesharedLogin aprintf-style manner. In order for the resulting log message to be logged theLogLevelmust be greater or equal than theLogLevelof thesharedLogand must be greater or equal than the globalLogLevel. Additionally theLogLevelmust be greater or equal than theLogLevelof thestdSharedLogger.- Parameters:
bool condition The condition must be truefor the data to be logged.string msg The printf-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);
- enum LogLevel: ubyte;
-
There are eight usable logging level. These level are all, trace, info, warning, error, critical, fatal, and off. If a log function with
LogLevel.fatalis called the shutdown handler of that logger is called.- all
-
Lowest possible assignable
LogLevel. - trace
-
LogLevelfor tracing the execution of the program. - info
-
This level is used to display information about the program.
- warning
-
warnings about the program should be displayed with this level.
- error
-
Information about errors should be logged with this level.
- critical
-
Messages that inform about critical errors should be logged with this level.
- fatal
-
Log messages that describe fatal errors should use this level.
- off
-
Highest possible
LogLevel.
- abstract class Logger;
-
This class is the base of every logger. In order to create a new kind of logger a deriving class needs to implement the
writeLogMsgmethod. By default this is not thread-safe.It is also possible to
overridethe three methodsbeginLogMsg,logMsgPartandfinishLogMsgtogether, this option gives more flexibility.- struct LogEntry;
-
LogEntry is a aggregation combining all information associated with a log message. This aggregation will be passed to the method writeLogMsg.
- string file;
-
the filename the log function was called from
- int line;
-
the line number the log function was called from
- string funcName;
-
the name of the function the log function was called from
- string prettyFuncName;
-
the pretty formatted name of the function the log function was called from
- string moduleName;
-
the name of the module the log message is coming from
- LogLevel logLevel;
-
the
LogLevelassociated with the log message - Tid threadId;
-
thread id of the log message
- SysTime timestamp;
-
the time the message was logged
- string msg;
-
the message of the log message
- Logger logger;
-
A refernce to the
Loggerused to create thisLogEntry
- @safe this(LogLevel lv);
-
Every subclass of
Loggerhas to call this constructor from their constructor. It sets theLogLevel, and creates a fatal handler. The fatal handler will throw anErrorif a log call is made with levelLogLevel.fatal.- Parameters:
LogLevel lvLogLevelto use for thisLoggerinstance.
- protected abstract @safe void writeLogMsg(ref LogEntry payload);
-
A custom logger must implement this method in order to work in a
MultiLoggerandArrayLogger.- Parameters:
LogEntry payloadAll information associated with call to log function.
- See Also:
- beginLogMsg, logMsgPart, finishLogMsg
- protected @safe void logMsgPart(scope const(char)[] msg);
-
Logs a part of the log message.
- protected @safe void finishLogMsg();
-
Signals that the message has been written and no more calls to
logMsgPartfollow. - final const pure @nogc @property @safe LogLevel logLevel();
final @nogc @property @safe void logLevel(const LogLevel lv); -
The
LogLeveldetermines if the log call are processed or dropped by theLogger. In order for the log call to be processed theLogLevelof the log call must be greater or equal to theLogLevelof thelogger.These two methods set and get the
LogLevelof the usedLogger.- Example
auto f = new FileLogger(stdout); f.logLevel = LogLevel.info; assert(f.logLevel == LogLevel.info);
- final @nogc @property @safe void delegate() fatalHandler();
final @nogc @property @safe void fatalHandler(void delegate() @safe fh); -
This
delegateis called in case a log message withLogLevel.fatalgets logged.By default an
Errorwill be thrown. - @trusted void forwardMsg(ref LogEntry payload);
-
This method allows forwarding log entries from one logger to another.
forwardMsgwill 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 theglobalLogLevelwont be evaluated again since it is assumed that the caller already checked that. - template memLogFunctions(LogLevel ll)
alias 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));
alias 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);
alias 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));
alias 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);
alias 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));
alias 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);
alias 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));
alias 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);
alias 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));
alias 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);
alias 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));
alias 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); -
This template provides the log functions for the
Loggerclasswith theLogLevelencoded in the function name.For further information see the the two functions defined inside of this template.
The aliases following this template create the public names of these log functions.- void logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args)
Constraints: if (args.length == 0 || args.length > 0 && !is(A[0] : bool)); -
This function logs data to the used
Logger.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLevel.- Parameters:
A argsThe 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");
- void logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args);
-
This function logs data to the used
Loggerdepending on a condition.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLeveladditionally the condition passed must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.A argsThe 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");
- void 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);
-
This function logs data to the used
Loggerin aprintf-style manner.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLeveladditionally the passed condition must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.string msgThe printf-style string.A argsThe 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);
- void logImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);
-
This function logs data to the used
Loggerin aprintf-style manner.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLevel.- Parameters:
string msgThe printf-style string.A argsThe 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);
- void logImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args)
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy bool condition, lazy A args)
Constraints: if (args.length != 1);
void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy bool condition, lazy T args, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__); -
This method logs data with the
LogLevelof the usedLogger.This method takes a
boolas first argument. In order for the data to be processed theboolmust betrueand theLogLevelof the Logger must be greater or equal to the globalLogLevel.- Parameters:
A argsThe data that should be logged. bool conditionThe condition must be truefor the data to be logged.A argsThe data that is to be logged.
- Returns:
- The logger used by the logging function as reference.
- Example
auto l = new StdioLogger(); l.log(1337);
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
Constraints: if (args.length > 1 && !is(Unqual!(A[0]) : bool) || args.length == 0);
void log(T)(const LogLevel ll, lazy T args, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__); -
This function logs data to the used
Loggerwith a specificLogLevel.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLevel.- Parameters:
LogLevel llThe specific LogLevelused for logging the log message.A argsThe 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");
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
Constraints: if (args.length != 1);
void log(T)(lazy bool condition, lazy T args, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__); -
This function logs data to the used
Loggerdepending on a explicitly passed condition with theLogLevelof the usedLogger.In order for the resulting log message to be logged the
LogLevelof the usedLoggermust be greater or equal than the globalLogLeveland the condition must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.A argsThe 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");
- void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args)
Constraints: if (args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(immutable(A[0]) == immutable(LogLevel)) || args.length == 0);
void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__); -
This function logs data to the used
Loggerwith theLogLevelof the usedLogger.In order for the resulting log message to be logged the
LogLevelof the usedLoggermust be greater or equal than the globalLogLevel.- Parameters:
A argsThe 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");
- void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy bool condition, lazy string msg, lazy A args);
-
This function logs data to the used
Loggerwith a specificLogLeveland depending on a condition in aprintf-style manner.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLeveland the condition must betrue.- Parameters:
LogLevel llThe specific LogLevelused for logging the log message.bool conditionThe condition must be truefor the data to be logged.string msgThe format string used for this log call. A argsThe 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");
- void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy string msg, lazy A args);
-
This function logs data to the used
Loggerwith a specificLogLevelin aprintf-style manner.In order for the resulting log message to be logged the
LogLevelmust be greater or equal than theLogLevelof the usedLoggerand must be greater or equal than the globalLogLevel.- Parameters:
LogLevel llThe specific LogLevelused for logging the log message.string msgThe format string used for this log call. A argsThe 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");
- void logf(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);
-
This function logs data to the used
Loggerdepending on a condition with theLogLevelof the usedLoggerin aprintf-style manner.In order for the resulting log message to be logged the
LogLevelof the usedLoggermust be greater or equal than the globalLogLeveland the condition must betrue.- Parameters:
bool conditionThe condition must be truefor the data to be logged.string msgThe format string used for this log call. A argsThe 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");
- void logf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args);
-
This method logs data to the used
Loggerwith theLogLevelof the thisLoggerin aprintf-style manner.In order for the data to be processed the
LogLevelof theLoggermust be greater or equal to the globalLogLevel.- Parameters:
string msgThe format string used for this log call. A argsThe 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");
-
This property sets and gets the default
Logger.- Example
sharedLog = new FileLogger(yourFile);
The example sets a newFileLoggeras newsharedLog. If at some point you want to use the original default logger again, you can usesharedLog = null;. This will put back the original.- Note
- While getting and setting
sharedLogis thread-safe, it has to be considered that the returned reference is only a current snapshot and in the following code, you must make sure no other thread reassigns to it between reading and writingsharedLog.
sharedLogis only thread-safe if the the usedLoggeris thread-safe. The defaultLoggeris thread-safe.if (sharedLog !is myLogger) sharedLog = new myLogger; - @nogc @property @safe LogLevel globalLogLevel();
@property @safe void globalLogLevel(LogLevel ll); -
This methods get and set the global
LogLevel.Every log message with a
LogLevellower as the globalLogLevelwill be discarded before it reacheswriteLogMessagemethod of anyLogger. - class StdForwardLogger: std.experimental.logger.core.Logger;
-
The
StdForwardLoggerwill always forward anything to the sharedLog.The
StdForwardLoggerwill not throw if data is logged withLogLevel.fatal.- Examples:
-
auto nl1 = new StdForwardLogger(LogLevel.all);
- @safe this(const LogLevel lv = LogLevel.all);
-
The default constructor for the
StdForwardLogger.- Parameters:
LogLevel lvThe LogLevelfor theMultiLogger. By default theLogLevelisall.
- @property @safe Logger stdThreadLocalLog();
@property @safe void stdThreadLocalLog(Logger logger); -
This function returns a thread unique
Logger, that by default propergates all data logged to it to thesharedLog.These properties can be used to set and get this
Logger. Every modification to thisLoggerwill only be visible in the thread the modification has been done from.
ThisLoggeris called by the free standing log functions. This allows to create thread local redirections and still use the free standing log functions.- Examples:
- Ditto
import std.experimental.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);
© 1999–2021 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/std_experimental_logger_core.html