This template evaluates if the passed LogLevel
is active. The previously described version statements are used to decide if the LogLevel
is active. The version statements only influence the compile unit they are used with, therefore this function can only disable logging this specific compile unit.
This compile-time flag is true
if logging is not statically disabled.
This functions is used at runtime to determine if a LogLevel
is 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
This template returns the LogLevel
named "logLevel" of type LogLevel
defined in a user defined module where the filename has the suffix "loggerconfig.d". This LogLevel
sets the minimal LogLevel
of the module.
A minimal LogLevel
can be defined on a per module basis. In order to define a module LogLevel
a 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 a LogLevel
called logLevel this LogLevel
will be used. This parent lookup is continued until there is no parent module. Then the moduleLogLevel is LogLevel.all
.
static assert(moduleLogLevel!"" == LogLevel.all);
static assert(moduleLogLevel!"not.amodule.path" == LogLevel.all);
This function logs data.
In order for the data to be processed, the LogLevel
of the log call must be greater or equal to the LogLevel
of the sharedLog
and the defaultLogLevel
; additionally the condition passed must be true
.
LogLevel ll
| The LogLevel used by this log call. |
bool condition
| The condition must be true for the data to be logged. |
A args
| The data that should be logged. |
log(LogLevel.warning, true, "Hello World", 3.1415);
This function logs data.
In order for the data to be processed the LogLevel
of the log call must be greater or equal to the LogLevel
of the sharedLog
.
LogLevel ll
| The LogLevel used by this log call. |
A args
| The data that should be logged. |
log(LogLevel.warning, "Hello World", 3.1415);
This function logs data.
In order for the data to be processed the LogLevel
of the sharedLog
must be greater or equal to the defaultLogLevel
add the condition passed must be true
.
bool condition
| The condition must be true for the data to be logged. |
A args
| The data that should be logged. |
log(true, "Hello World", 3.1415);
This function logs data.
In order for the data to be processed the LogLevel
of the sharedLog
must be greater or equal to the defaultLogLevel
.
A args
| The data that should be logged. |
log("Hello World", 3.1415);
This function logs data in a printf
-style manner.
In order for the data to be processed the LogLevel
of the log call must be greater or equal to the LogLevel
of the sharedLog
and the defaultLogLevel
additionally the condition passed must be true
.
LogLevel ll
| The LogLevel used by this log call. |
bool condition
| The condition must be true for the data to be logged. |
string msg
| The printf -style string. |
A args
| The data that should be logged. |
logf(LogLevel.warning, true, "Hello World %f", 3.1415);
This function logs data in a printf
-style manner.
In order for the data to be processed the LogLevel
of the log call must be greater or equal to the LogLevel
of the sharedLog
and the defaultLogLevel
.
LogLevel ll
| The LogLevel used by this log call. |
string msg
| The printf -style string. |
A args
| The data that should be logged. |
logf(LogLevel.warning, "Hello World %f", 3.1415);
This function logs data in a printf
-style manner.
In order for the data to be processed the LogLevel
of the log call must be greater or equal to the defaultLogLevel
additionally the condition passed must be true
.
bool condition
| The condition must be true for the data to be logged. |
string msg
| The printf -style string. |
A args
| The data that should be logged. |
logf(true, "Hello World %f", 3.1415);
This function logs data in a printf
-style manner.
In order for the data to be processed the LogLevel
of the log call must be greater or equal to the defaultLogLevel
.
string msg
| The printf -style string. |
A args
| The data that should be logged. |
logf("Hello World %f", 3.1415);
This template provides the global log functions with the LogLevel
is encoded in the function name.
The aliases following this template create the public names of these log functions.
This function logs data to the stdThreadLocalLog
, optionally depending on a condition.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the stdThreadLocalLog
and must be greater or equal than the global LogLevel
. Additionally the LogLevel
must be greater or equal than the LogLevel
of the stdSharedLogger
. If a condition is given, it must evaluate to true
.
bool condition | The condition must be true for the data to be logged. |
A args | The data that should be logged. |
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");
This template provides the global printf
-style log functions with the LogLevel
is encoded in the function name.
The aliases following this template create the public names of the log functions.
This function logs data to the sharedLog
in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the sharedLog
and must be greater or equal than the global LogLevel
. Additionally the LogLevel
must be greater or equal than the LogLevel
of the stdSharedLogger
.
string msg | The printf -style string. |
A args | The data that should be logged. |
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 the
sharedLog
in a printf
-style manner. In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the sharedLog
and must be greater or equal than the global LogLevel
. Additionally the LogLevel
must be greater or equal than the LogLevel
of the stdSharedLogger
. bool condition | The condition must be true for the data to be logged. |
string msg | The printf -style string. |
A args | The data that should be logged. |
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);
There are eight usable logging level. These level are all, trace, info, warning, error, critical, fatal, and off. If a log function with LogLevel.fatal
is called the shutdown handler of that logger is called.
Lowest possible assignable LogLevel
.
LogLevel
for tracing the execution of the program.
This level is used to display information about the program.
warnings about the program should be displayed with this level.
Information about errors should be logged with this level.
Messages that inform about critical errors should be logged with this level.
Log messages that describe fatal errors should use this level.
Highest possible LogLevel
.
This class is the base of every logger. In order to create a new kind of logger a deriving class needs to implement the writeLogMsg
method. By default this is not thread-safe.
It is also possible to override
the three methods beginLogMsg
, logMsgPart
and finishLogMsg
together, this option gives more flexibility.
LogEntry is a aggregation combining all information associated with a log message. This aggregation will be passed to the method writeLogMsg.
the filename the log function was called from
the line number the log function was called from
the name of the function the log function was called from
the pretty formatted name of the function the log function was called from
the name of the module the log message is coming from
the LogLevel
associated with the log message
thread id of the log message
the time the message was logged
the message of the log message
A refernce to the Logger
used to create this LogEntry
Every subclass of Logger
has to call this constructor from their constructor. It sets the LogLevel
, and creates a fatal handler. The fatal handler will throw an Error
if a log call is made with level LogLevel.fatal
.
LogLevel lv
|
LogLevel to use for this Logger instance. |
A custom logger must implement this method in order to work in a MultiLogger
and ArrayLogger
.
LogEntry payload
| All information associated with call to log function. |
Logs a part of the log message.
Signals that the message has been written and no more calls to logMsgPart
follow.
The LogLevel
determines if the log call are processed or dropped by the Logger
. In order for the log call to be processed the LogLevel
of the log call must be greater or equal to the LogLevel
of the logger
.
These two methods set and get the LogLevel
of the used Logger
.
auto f = new FileLogger(stdout); f.logLevel = LogLevel.info; assert(f.logLevel == LogLevel.info);
This delegate
is called in case a log message with LogLevel.fatal
gets logged.
By default an Error
will be thrown.
This method allows forwarding log entries from one logger to another.
forwardMsg
will ensure proper synchronization and then call writeLogMsg
. 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 the globalLogLevel
wont be evaluated again since it is assumed that the caller already checked that.
This template provides the log functions for the Logger
class
with the LogLevel
encoded 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.
This function logs data to the used Logger
.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
.
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
depending on a condition.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
additionally the condition passed must be true
.
bool condition
| The condition must be true for the data to be logged. |
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
additionally the passed condition must be true
.
bool condition
| The condition must be true for the data to be logged. |
string msg
| The printf -style string. |
A args
| The data that should be logged. |
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);
This function logs data to the used Logger
in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
.
string msg
| The printf -style string. |
A args
| The data that should be logged. |
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);
This method logs data with the LogLevel
of the used Logger
.
This method takes a bool
as first argument. In order for the data to be processed the bool
must be true
and the LogLevel
of the Logger must be greater or equal to the global LogLevel
.
A args
| The data that should be logged. |
bool condition
| The condition must be true for the data to be logged. |
A args
| The data that is to be logged. |
auto l = new StdioLogger(); l.log(1337);
This function logs data to the used Logger
with a specific LogLevel
.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
.
LogLevel ll
| The specific LogLevel used for logging the log message. |
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
depending on a explicitly passed condition with the LogLevel
of the used Logger
.
In order for the resulting log message to be logged the LogLevel
of the used Logger
must be greater or equal than the global LogLevel
and the condition must be true
.
bool condition
| The condition must be true for the data to be logged. |
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
with the LogLevel
of the used Logger
.
In order for the resulting log message to be logged the LogLevel
of the used Logger
must be greater or equal than the global LogLevel
.
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
with a specific LogLevel
and depending on a condition in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
and the condition must be true
.
LogLevel ll
| The specific LogLevel used for logging the log message. |
bool condition
| The condition must be true for the data to be logged. |
string msg
| The format string used for this log call. |
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
with a specific LogLevel
in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
must be greater or equal than the LogLevel
of the used Logger
and must be greater or equal than the global LogLevel
.
LogLevel ll
| The specific LogLevel used for logging the log message. |
string msg
| The format string used for this log call. |
A args
| The data that should be logged. |
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");
This function logs data to the used Logger
depending on a condition with the LogLevel
of the used Logger
in a printf
-style manner.
In order for the resulting log message to be logged the LogLevel
of the used Logger
must be greater or equal than the global LogLevel
and the condition must be true
.
bool condition
| The condition must be true for the data to be logged. |
string msg
| The format string used for this log call. |
A args
| The data that should be logged. |
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");
This method logs data to the used Logger
with the LogLevel
of the this Logger
in a printf
-style manner.
In order for the data to be processed the LogLevel
of the Logger
must be greater or equal to the global LogLevel
.
string msg
| The format string used for this log call. |
A args
| The data that should be logged. |
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
.
sharedLog = new FileLogger(yourFile);The example sets a new
FileLogger
as new sharedLog
. If at some point you want to use the original default logger again, you can use sharedLog = null;
. This will put back the original. sharedLog
is 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 writing sharedLog
. sharedLog
is only thread-safe if the the used Logger
is thread-safe. The default Logger
is thread-safe. if (sharedLog !is myLogger) sharedLog = new myLogger;
This methods get and set the global LogLevel
.
Every log message with a LogLevel
lower as the global LogLevel
will be discarded before it reaches writeLogMessage
method of any Logger
.
The StdForwardLogger
will always forward anything to the sharedLog.
The StdForwardLogger
will not throw if data is logged with LogLevel.fatal
.
auto nl1 = new StdForwardLogger(LogLevel.all);
The default constructor for the StdForwardLogger
.
LogLevel lv
| The LogLevel for the MultiLogger . By default the LogLevel is all . |
This function returns a thread unique Logger
, that by default propergates all data logged to it to the sharedLog
.
These properties can be used to set and get this Logger
. Every modification to this Logger
will only be visible in the thread the modification has been done from.
This Logger
is called by the free standing log functions. This allows to create thread local redirections and still use the free standing log functions.
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–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/std_experimental_logger_core.html