Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.logger.core

Sourcestd/logger/core.d

@safe boolisLoggingEnabled()(LogLevelll, LogLevelloggerLL, LogLevelglobalLL, lazy boolcondition = true);
This functions is used at runtime to determine if aLogLevel isactive. The same previously defined version statements are used to disablecertain levels. Again the version statements are associated with a compileunit and can therefore not disable logging in other compile units.pure bool isLoggingEnabled()(LogLevel ll) @safe nothrow @nogc
voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy Aargs)
if (args.length != 1);

voidlog(T, string moduleName = __MODULE__)(const LogLevelll, lazy boolcondition, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);
This function logs data.
In order for the data to be processed, theLogLevel of the log call mustbe greater or equal to theLogLevel of thesharedLog and thedefaultLogLevel; additionally the condition passed must betrue.
Parameters:
LogLevelllTheLogLevel used by this log call.
boolconditionThe condition must betrue for the data to be logged.
AargsThe data that should be logged.

Example

log(LogLevel.warning,true,"Hello World", 3.1415);

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy Aargs)
if (args.length > 1 && !is(Unqual!(A[0]) : bool));

voidlog(T, string moduleName = __MODULE__)(const LogLevelll, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);
This function logs data.
In order for the data to be processed theLogLevel of the log call mustbe greater or equal to theLogLevel of thesharedLog.
Parameters:
LogLevelllTheLogLevel used by this log call.
AargsThe data that should be logged.

Example

log(LogLevel.warning,"Hello World", 3.1415);

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs)
if (args.length != 1);

voidlog(T, string moduleName = __MODULE__)(lazy boolcondition, lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);
This function logs data.
In order for the data to be processed theLogLevel of thesharedLog must be greater or equal to thedefaultLogLeveladd the condition passed must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
AargsThe data that should be logged.

Example

log(true,"Hello World", 3.1415);

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)
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 theLogLevel of thesharedLog must be greater or equal to thedefaultLogLevel.
Parameters:
AargsThe data that should be logged.

Example

log("Hello World", 3.1415);

voidlogf(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);
This function logs data in aprintf-style manner.
In order for the data to be processed theLogLevel of the log call mustbe greater or equal to theLogLevel of thesharedLog and thedefaultLogLevel additionally the condition passed must betrue.
Parameters:
LogLevelllTheLogLevel used by this log call.
boolconditionThe condition must betrue for the data to be logged.
stringmsgTheprintf-style string.
AargsThe data that should be logged.

Example

logf(LogLevel.warning,true,"Hello World %f", 3.1415);

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy stringmsg, lazy Aargs);
This function logs data in aprintf-style manner.
In order for the data to be processed theLogLevel of the log call mustbe greater or equal to theLogLevel of thesharedLog and thedefaultLogLevel.
Parameters:
LogLevelllTheLogLevel used by this log call.
stringmsgTheprintf-style string.
AargsThe data that should be logged.

Example

logf(LogLevel.warning,"Hello World %f", 3.1415);

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);
This function logs data in aprintf-style manner.
In order for the data to be processed theLogLevel of the log call mustbe greater or equal to thedefaultLogLevel additionally the conditionpassed must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
stringmsgTheprintf-style string.
AargsThe data that should be logged.

Example

logf(true,"Hello World %f", 3.1415);

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);
This function logs data in aprintf-style manner.
In order for the data to be processed theLogLevel of the log call mustbe greater or equal to thedefaultLogLevel.
Parameters:
stringmsgTheprintf-style string.
AargsThe data that should be logged.

Example

logf("Hello World %f", 3.1415);

templatedefaultLogFunction(LogLevel ll)
This template provides the global log functions with theLogLevelis encoded in the function name.
The aliases following this template create the public names of these logfunctions.
aliastrace = 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);

aliasinfo = 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);

aliaswarning = 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);

aliaserror = 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);

aliascritical = 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);

aliasfatal = 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 thestdThreadLocalLog, optionally dependingon a condition.
In order for the resulting log message to be logged theLogLevel mustbe greater or equal than theLogLevel of thestdThreadLocalLog andmust be greater or equal than the globalLogLevel.Additionally theLogLevel must be greater or equal than theLogLevelof thestdSharedLogger.If a condition is given, it must evaluate totrue.
Parameters:
bool conditionThe condition must betrue for the data to be logged.
A 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");

templatedefaultLogFunctionf(LogLevel ll)
This template provides the globalprintf-style log functions withtheLogLevel is encoded in the function name.
The aliases following this template create the public names of the logfunctions.
aliastracef = 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);

aliasinfof = 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);

aliaswarningf = 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);

aliaserrorf = 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);

aliascriticalf = 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);

aliasfatalf = 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 thesharedLog in aprintf-stylemanner.
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.
Parameters:
string msgTheprintf-style string.
A 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 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.

Parameters:
bool conditionThe condition must betrue for the data to be logged.
string msgTheprintf-style string.
A argsThe 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);

enumLogLevel: ubyte;
There are eight usable logging level. These level areall,trace,info,warning,error,critical,fatal, andoff.If a log function withLogLevel.fatal is called the shutdown handler ofthat logger is called.
all
Lowest possible assignableLogLevel.
trace
LogLevel for 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 possibleLogLevel.
abstract classLogger;
This class is the base of every logger. In order to create a new kind oflogger a deriving class needs to implement thewriteLogMsg method. Bydefault this is not thread-safe.
It is also possible tooverride the three methodsbeginLogMsg,logMsgPart andfinishLogMsg together, this option gives moreflexibility.
structLogEntry;
LogEntry is a aggregation combining all information associated with a log message. This aggregation will be passed to the method writeLogMsg.
stringfile;
the filename the log function was called from
intline;
the line number the log function was called from
stringfuncName;
the name of the function the log function was called from
stringprettyFuncName;
the pretty formatted name of the function the log function wascalled from
stringmoduleName;
the name of the module the log message is coming from
LogLevellogLevel;
theLogLevel associated with the log message
TidthreadId;
thread id of the log message
SysTimetimestamp;
the time the message was logged
stringmsg;
the message of the log message
Loggerlogger;
A refernce to theLogger used to create thisLogEntry
this(this This)(LogLevellv);
Every subclass ofLogger has to call this constructor from their constructor. It sets theLogLevel, and creates a fatal handler. The fatal handler will throw anError if a log call is made with levelLogLevel.fatal.
Parameters:
LogLevellvLogLevel to use for thisLogger instance.
protected abstract @safe voidwriteLogMsg(ref LogEntrypayload);
A custom logger must implement this method in order to work in aMultiLogger andArrayLogger.
Parameters:
LogEntrypayloadAll information associated with call to log function.
See Also:
beginLogMsg, logMsgPart, finishLogMsg
protected @safe voidlogMsgPart(scope const(char)[]msg);
Logs a part of the log message.
protected @safe voidfinishLogMsg();
Signals that the message has been written and no more calls tologMsgPart follow.
final pure @nogc @property @safe LogLevellogLevel() const;

final @nogc @property @safe voidlogLevel(const LogLevellv);
TheLogLevel determines if the log call are processed or dropped by theLogger. In order for the log call to be processed theLogLevel of the log call must be greater or equal to theLogLevel of thelogger.
These two methods set and get theLogLevel of 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 voidfatalHandler(void delegate() @safefh);
Thisdelegate is called in case a log message withLogLevel.fatal gets logged.
By default anError will be thrown.
@trusted voidforwardMsg(ref LogEntrypayload);
This method allows forwarding log entries from one logger to another.
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.
templatememLogFunctions(LogLevel ll)

aliastrace = .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));

aliastracef = .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);

aliasinfo = .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));

aliasinfof = .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);

aliaswarning = .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));

aliaswarningf = .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);

aliaserror = .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));

aliaserrorf = .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);

aliascritical = .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));

aliascriticalf = .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);

aliasfatal = .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));

aliasfatalf = .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 theLoggerclass with theLogLevel encoded in the function name.
For further information see the two functions defined inside of this template.
The aliases following this template create the public names of these log functions.
voidlogImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)
if (args.length == 0 ||args.length > 0 && !is(A[0] : bool));
This function logs data to the usedLogger.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel.
Parameters:
AargsThe 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");

voidlogImpl(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs);
This function logs data to the usedLogger depending on a condition.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel additionally the condition passed must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
AargsThe 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");

voidlogImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);
This function logs data to the usedLogger in aprintf-style manner.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel additionally the passed condition must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
stringmsgTheprintf-style string.
AargsThe 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);

voidlogImplf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);
This function logs data to the usedLogger in aprintf-style manner.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel.
Parameters:
stringmsgTheprintf-style string.
AargsThe 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);

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy boolcondition, lazy Aargs)
if (args.length != 1);

voidlog(T, string moduleName = __MODULE__)(const LogLevelll, lazy boolcondition, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__);
This method logs data with theLogLevel of the usedLogger.
This method takes abool as first argument. In order for the data to be processed thebool must betrue and theLogLevel of the Logger must be greater or equal to the globalLogLevel.
Parameters:
AargsThe data that should be logged.
boolconditionThe condition must betrue for the data to be logged.
AargsThe data that is to be logged.
Returns:
The logger used by the logging function as reference.

Example

auto l =new StdioLogger();l.log(1337);

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy Aargs)
if (args.length > 1 && !is(Unqual!(A[0]) : bool) ||args.length == 0);

voidlog(T)(const LogLevelll, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);
This function logs data to the usedLogger with a specificLogLevel.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel.
Parameters:
LogLevelllThe specificLogLevel used for logging the log message.
AargsThe 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");

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy Aargs)
if (args.length != 1);

voidlog(T)(lazy boolcondition, lazy Targs, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);
This function logs data to the usedLogger depending on a explicitly passed condition with theLogLevel of the usedLogger.
In order for the resulting log message to be logged theLogLevel of the usedLogger must be greater or equal than the globalLogLevel and the condition must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
AargsThe 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");

voidlog(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy Aargs)
if (args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(immutable(A[0]) == immutable(LogLevel)) ||args.length == 0);

voidlog(T)(lazy Targ, intline = __LINE__, stringfile = __FILE__, stringfuncName = __FUNCTION__, stringprettyFuncName = __PRETTY_FUNCTION__, stringmoduleName = __MODULE__);
This function logs data to the usedLogger with theLogLevel of the usedLogger.
In order for the resulting log message to be logged theLogLevel of the usedLogger must be greater or equal than the globalLogLevel.
Parameters:
AargsThe 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");

voidlogf(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);
This function logs data to the usedLogger with a specificLogLevel and depending on a condition in aprintf-style manner.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel and the condition must betrue.
Parameters:
LogLevelllThe specificLogLevel used for logging the log message.
boolconditionThe condition must betrue for the data to be logged.
stringmsgThe format string used for this log call.
AargsThe 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");

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(const LogLevelll, lazy stringmsg, lazy Aargs);
This function logs data to the usedLogger with a specificLogLevel in aprintf-style manner.
In order for the resulting log message to be logged theLogLevel must be greater or equal than theLogLevel of the usedLogger and must be greater or equal than the globalLogLevel.
Parameters:
LogLevelllThe specificLogLevel used for logging the log message.
stringmsgThe format string used for this log call.
AargsThe 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");

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy boolcondition, lazy stringmsg, lazy Aargs);
This function logs data to the usedLogger depending on a condition with theLogLevel of the usedLogger in aprintf-style manner.
In order for the resulting log message to be logged theLogLevel of the usedLogger must be greater or equal than the globalLogLevel and the condition must betrue.
Parameters:
boolconditionThe condition must betrue for the data to be logged.
stringmsgThe format string used for this log call.
AargsThe 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");

voidlogf(int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__, A...)(lazy stringmsg, lazy Aargs);
This method logs data to the usedLogger with theLogLevel of the thisLogger in aprintf-style manner.
In order for the data to be processed theLogLevel of theLogger must be greater or equal to the globalLogLevel.
Parameters:
stringmsgThe format string used for this log call.
AargsThe 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");

@property @safe shared(Logger)sharedLog();

@property @safe voidsharedLog(shared(Logger)logger);
This property sets and gets the defaultLogger. Unless set to anotherlogger by the user, the default logger's log level is LogLevel.info.

Example

sharedLog =newshared FileLogger(yourFile);
The example sets a newFileLogger as newsharedLog.
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;

@nogc @property @safe LogLevelglobalLogLevel();

@property @safe voidglobalLogLevel(LogLevelll);
These methods get and set the globalLogLevel.
Every log message with aLogLevel lower than the globalLogLevelwill be discarded before it reacheswriteLogMessage method of anyLogger.
classStdForwardLogger:std.logger.core.Logger;
TheStdForwardLogger will always forward anything to the sharedLog.
TheStdForwardLogger will not throw if data is logged withLogLevel.fatal.
Examples:
auto nl1 =newStdForwardLogger(LogLevel.all);
@safe this(const LogLevellv = LogLevel.all);
The default constructor for theStdForwardLogger.
Parameters:
LogLevellvTheLogLevel for theMultiLogger. By default the LogLevel isall.
@property @safe LoggerstdThreadLocalLog();

@property @safe voidstdThreadLocalLog(Loggerlogger);
This function returns a thread uniqueLogger, that by defaultpropagates all data logged to it to thesharedLog.
These properties can be used to set and get thisLogger. Everymodification to thisLogger will only be visible in the thread themodification has been done from.
ThisLogger is called by the free standing log functions. This allows tocreate thread local redirections and still use the free standing logfunctions.
Examples:
Ditto
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);
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:59:16 2026

[8]ページ先頭

©2009-2026 Movatter.jp