std.logger.core

Types 17

aliastrace = defaultLogFunction!(LogLevel.trace)

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.

Parameters

conditionThe condition must be true for the data to be logged.
argsThe 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"); --------------------
aliasinfo = defaultLogFunction!(LogLevel.info)

Ditto

aliaswarning = defaultLogFunction!(LogLevel.warning)

Ditto

aliaserror = defaultLogFunction!(LogLevel.error)

Ditto

aliascritical = defaultLogFunction!(LogLevel.critical)

Ditto

aliasfatal = defaultLogFunction!(LogLevel.fatal)

Ditto

aliastracef = defaultLogFunctionf!(LogLevel.trace)

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.

Parameters

msgThe printf-style string.
argsThe 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 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.

Params: condition = The condition must be true for the data to be logged. msg = The printf-style string. 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); --------------------

aliasinfof = defaultLogFunctionf!(LogLevel.info)

Ditto

aliaswarningf = defaultLogFunctionf!(LogLevel.warning)

Ditto

aliaserrorf = defaultLogFunctionf!(LogLevel.error)

Ditto

aliascriticalf = defaultLogFunctionf!(LogLevel.critical)

Ditto

aliasfatalf = defaultLogFunctionf!(LogLevel.fatal)

Ditto

private structMsgRange
Fields
private Logger log
Methods
void put(T)(T msg) if (isSomeString!T) @safe
void put(dchar elem) @safe
Constructors
enumLogLevel : 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.fatal is called the shutdown handler of that logger is called.

all = 1Lowest possible assignable `LogLevel`.
trace = 32`LogLevel` for tracing the execution of the program.
info = 64This level is used to display information about the program.
warning = 96warnings about the program should be displayed with this level.
error = 128Information about errors should be logged with this level.
critical = 160Messages that inform about critical errors should be logged with this level.
fatal = 192Log messages that describe fatal errors should use this level.
off = ubyte.maxHighest possible `LogLevel`.
classLogger

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.

Fields
private void delegate() @safe fatalHandler_
private LogLevel logLevel_
private Mutex mutex
Appender!string msgAppender
LogEntry header
Methods
void writeLogMsg(ref LogEntry payload) @safeA custom logger must implement this method in order to work in a `MultiLogger` and `ArrayLogger`.
void beginLogMsg(string file, int line, string funcName, string prettyFuncName, string moduleName, LogLevel logLevel, Tid threadId, SysTime timestamp, Logger logger) @safe
void logMsgPart(scope const(char)[] msg) @safeLogs a part of the log message.
void finishLogMsg() @safeSignals that the message has been written and no more calls to `logMsgPart` follow.
LogLevel logLevel() @property const pure @safe @nogcThe `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 `LogLeve...
void logLevel(const LogLevel lv) @property @safe @nogcDitto
void delegate() fatalHandler() @property @safe @nogcThis `delegate` is called in case a log message with `LogLevel.fatal` gets logged.
void fatalHandler(void delegate() @safe fh) @property @safe @nogcDitto
void forwardMsg(ref LogEntry payload) @trustedThis method allows forwarding log entries from one logger to another.
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) if (args.length != 1)This method logs data with the `LogLevel` of the used `Logger`.
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__)Ditto
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) if ((args.length > 1 && !is(Unqual!(A[0]) : bool)) || args.length == 0)This function logs data to the used `Logger` with a specific `LogLevel`.
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__)Ditto
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) if (args.length != 1)This function logs data to the used `Logger` depending on a explicitly passed condition with the `LogLevel` of the used `Logger`.
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__)Ditto
void log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if ((args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(immutable A[0] == immutable LogLevel)) || args.length == 0)This function logs data to the used `Logger` with the `LogLevel` of the used `Logger`.
void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__)Ditto
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 `Logger` with a specific `LogLevel` and depending on a condition in a `printf`-style manner.
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 `Logger` with a specific `LogLevel` in a `printf`-style manner.
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 `Logger` depending on a condition with the `LogLevel` of the used `Logger` in a `printf`-style manner.
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 `Logger` with the `LogLevel` of the this `Logger` in a `printf`-style manner.
Constructors
this(LogLevel lv)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 wi...
Nested Templates
LogEntryLogEntry is a aggregation combining all information associated with a log message. This aggregation will be passed to the method writeLogMsg.
memLogFunctions(LogLevel ll)This template provides the log functions for the `Logger` `class` with the `LogLevel` encoded in the function name.

The StdForwardLogger will always forward anything to the sharedLog.

The StdForwardLogger will not throw if data is logged with LogLevel.fatal.

Methods
void writeLogMsg(ref LogEntry payload) @trusted
Constructors
this(const LogLevel lv = LogLevel.all)The default constructor for the `StdForwardLogger`.
Fields
int line
string file
string func
string prettyFunc
string msg
Methods
void writeLogMsg(ref LogEntry payload) @safe
Constructors
this(const LogLevel lv = LogLevel.all)

Functions 25

fnbool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, LogLevel globalLL, lazy bool condition = true) @safeThis 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 associa...
fnvoid systimeToISOString(OutputRange)(OutputRange o, const ref SysTime time) if (isOutputRange!(OutputRange, string))
fnvoid 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) if (args.length != 1)This function logs data.
fnvoid 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__)Ditto
fnvoid log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args) if (args.length > 1 && !is(Unqual!(A[0]) : bool))This function logs data.
fnvoid log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__)Ditto
fnvoid log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args) if (args.length != 1)This function logs data.
fnvoid log(T, string moduleName = __MODULE__)(lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__)Ditto
fnvoid log(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy A args) if ((args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(Unqual!(A[0]) == LogLevel)) || args.length == 0)This function logs data.
fnvoid log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__)
fnvoid 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.
fnvoid 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.
fnvoid 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.
fnvoid 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.
private fnvoid formatString(A...)(MsgRange oRange, A args)
private fnshared(Logger) defaultSharedLoggerImpl() @property @trusted
fnshared(Logger) sharedLog() @property @safeThis property sets and gets the default `Logger`. Unless set to another logger by the user, the default logger's log level is LogLevel.info.
fnvoid sharedLog(shared(Logger) logger) @property @safeDitto
fnLogLevel globalLogLevel() @property @safe @nogcThese methods get and set the global `LogLevel`.
fnvoid globalLogLevel(LogLevel ll) @property @safeDitto
private fnLogger stdThreadLocalLogImpl() @property @trusted
fnLogger stdThreadLocalLog() @property @safeThis function returns a thread unique `Logger`, that by default propagates all data logged to it to the `sharedLog`.
fnvoid stdThreadLocalLog(Logger logger) @property @safeDitto
private fnauto trustedLoad(T)(ref shared T value) @trusted
private fnvoid trustedStore(T)(ref shared T dst, ref T src) @trusted

Variables 5

private varLogger stdSharedDefaultLogger
private varLogger stdSharedLogger
private varLogLevel stdLoggerGlobalLogLevel
private varLogger stdLoggerThreadLogger

This LogLevel is unqiue to every thread.

The thread local Logger will use this LogLevel to filter log calls every same way as presented earlier.

private varLogger stdLoggerDefaultThreadLogger

Templates 2

tmpldefaultLogFunction(LogLevel ll)

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.

Functions
void 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)
void defaultLogFunction(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
tmpldefaultLogFunctionf(LogLevel ll)

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.

Functions
void defaultLogFunctionf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)
void defaultLogFunctionf(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)