// Written in the D programming language./**Source: $(PHOBOSSRC std/logger/core.d)*/module std.logger.core; import core.atomic : atomicLoad, atomicOp, atomicStore, MemoryOrder;import core.sync.mutex : Mutex;import std.datetime.date : DateTime;import std.datetime.systime : Clock, SysTime;import std.range.primitives;import std.traits; import std.logger.filelogger; /+ Don’t forget to update the documentation of `std.logger` (`package.d`) when changing this test. This is a copy of example code found in its doc comment. +/@system unittest{ assert(globalLogLevel == LogLevel.all); assert((cast() sharedLog).logLevel == LogLevel.info);} /** This functions is used at runtime to determine if a `LogLevel` 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*/bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, LogLevel globalLL, lazy bool condition = true) @safe{ return ll >= globalLL && ll >= loggerLL && ll != LogLevel.off && globalLL != LogLevel.off && loggerLL != LogLevel.off && condition;} /* This function formates a `SysTime` into an `OutputRange`. The `SysTime` is formatted similar to$(LREF std.datatime.DateTime.toISOExtString) except the fractional second part.The fractional second part is in milliseconds and is always 3 digits.*/void systimeToISOString(OutputRange)(OutputRange o, const ref SysTime time)if (isOutputRange!(OutputRange,string)){ import std.format.write : formattedWrite; const auto dt = cast(DateTime) time; const auto fsec = time.fracSecs.total!"msecs"; formattedWrite(o, "%04d-%02d-%02dT%02d:%02d:%02d.%03d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, fsec);} /** This function logs data. In order for the data to be processed, the `LogLevel` of the log call mustbe greater or equal to the `LogLevel` of the `sharedLog` and the`defaultLogLevel`; additionally the condition passed must be `true`. Params: ll = The `LogLevel` used by this log call. condition = The condition must be `true` for the data to be logged. args = The 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 bool condition, lazy A args)if (args.length != 1){ stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (ll, condition, args);} /// Dittovoid 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__){ stdThreadLocalLog.log!(T,moduleName)(ll, condition, arg, line, file, funcName, prettyFuncName);} /** This function logs data. In order for the data to be processed the `LogLevel` of the log call mustbe greater or equal to the `LogLevel` of the `sharedLog`. Params: ll = The `LogLevel` used by this log call. args = The 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...)(const LogLevel ll, lazy A args)if (args.length > 1 && !is(Unqual!(A[0]) : bool)){ stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (ll, args);} /// Dittovoid log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__){ stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName, moduleName);} /** 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`. Params: condition = The condition must be `true` for the data to be logged. args = The 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 bool condition, lazy A args)if (args.length != 1){ stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, condition, args);} /// Dittovoid log(T, string moduleName = __MODULE__)(lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__){ stdThreadLocalLog.log!(T,moduleName)(stdThreadLocalLog.logLevel, condition, arg, line, file, funcName, prettyFuncName);} /** 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`. Params: args = The data that should be logged. Example:--------------------log("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)if ((args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(Unqual!(A[0]) == LogLevel)) || args.length == 0){ stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args);} void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__){ stdThreadLocalLog.log!T(stdThreadLocalLog.logLevel, arg, line, file, funcName, prettyFuncName, moduleName);} /** This function logs data in a `printf`-style manner. In order for the data to be processed the `LogLevel` of the log call mustbe greater or equal to the `LogLevel` of the `sharedLog` and the`defaultLogLevel` additionally the condition passed must be `true`. Params: ll = The `LogLevel` used by this log call. 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:--------------------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 bool condition, lazy string msg, lazy A args){ stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (ll, condition, msg, args);} /** This function logs data in a `printf`-style manner. In order for the data to be processed the `LogLevel` of the log call mustbe greater or equal to the `LogLevel` of the `sharedLog` and the`defaultLogLevel`. Params: ll = The `LogLevel` used by this log call. msg = The `printf`-style string. args = The 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...)(const LogLevel ll, lazy string msg, lazy A args){ stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (ll, msg, args);} /** This function logs data in a `printf`-style manner. In order for the data to be processed the `LogLevel` of the log call mustbe greater or equal to the `defaultLogLevel` additionally the conditionpassed must be `true`. 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:--------------------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 bool condition, lazy string msg, lazy A args){ stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, condition, msg, args);} /** This function logs data in a `printf`-style manner. In order for the data to be processed the `LogLevel` of the log call mustbe greater or equal to the `defaultLogLevel`. Params: msg = The `printf`-style string. args = The data that should be logged. Example:--------------------logf("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){ stdThreadLocalLog.logf!(line, file, funcName,prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, msg, args);} /** 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 logfunctions.*/template defaultLogFunction(LogLevel ll){ 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) { stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(args); } 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) { stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(condition, args); }} /** This function logs data to the `stdThreadLocalLog`, optionally dependingon a condition. In order for the resulting log message to be logged the `LogLevel` mustbe greater or equal than the `LogLevel` of the `stdThreadLocalLog` andmust 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`. Params: condition = The condition must be `true` for the data to be logged. 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");--------------------*/alias trace = defaultLogFunction!(LogLevel.trace);/// Dittoalias info = defaultLogFunction!(LogLevel.info);/// Dittoalias warning = defaultLogFunction!(LogLevel.warning);/// Dittoalias error = defaultLogFunction!(LogLevel.error);/// Dittoalias critical = defaultLogFunction!(LogLevel.critical);/// Dittoalias fatal = defaultLogFunction!(LogLevel.fatal); /** This template provides the global `printf`-style log functions withthe `LogLevel` is encoded in the function name. The aliases following this template create the public names of the logfunctions.*/template defaultLogFunctionf(LogLevel ll){ 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) { stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(msg, 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) { stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(condition, msg, args); }} /** This function logs data to the `sharedLog` in a `printf`-stylemanner. In order for the resulting log message to be logged the `LogLevel` mustbe greater or equal than the `LogLevel` of the `sharedLog` andmust be greater or equal than the global `LogLevel`.Additionally the `LogLevel` must be greater or equal than the `LogLevel`of the `stdSharedLogger`. Params: msg = The `printf`-style string. 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 the `sharedLog` in a $(Dprintf)-style manner. In order for the resulting log message to be logged the `LogLevel` mustbe greater or equal than the `LogLevel` of the `sharedLog` andmust 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);--------------------*/alias tracef = defaultLogFunctionf!(LogLevel.trace);/// Dittoalias infof = defaultLogFunctionf!(LogLevel.info);/// Dittoalias warningf = defaultLogFunctionf!(LogLevel.warning);/// Dittoalias errorf = defaultLogFunctionf!(LogLevel.error);/// Dittoalias criticalf = defaultLogFunctionf!(LogLevel.critical);/// Dittoalias fatalf = defaultLogFunctionf!(LogLevel.fatal); private struct MsgRange{ import std.traits : isSomeString, isSomeChar; private Logger log; this(Logger log) @safe { this.log = log; } void put(T)(T msg) @safe if (isSomeString!T) { log.logMsgPart(msg); } void put(dchar elem) @safe { import std.utf : encode; char[4] buffer; size_t len = encode(buffer, elem); log.logMsgPart(buffer[0 .. len]); }} private void formatString(A...)(MsgRange oRange, A args){ import std.format.write : formattedWrite; foreach (arg; args) { formattedWrite(oRange, "%s", arg); }} @system unittest{ void dummy() @safe { auto tl = new TestLogger(); auto dst = MsgRange(tl); formatString(dst, "aaa", "bbb"); } dummy();} /**There are eight usable logging level. These level are $(I all), $(I trace),$(I info), $(I warning), $(I error), $(I critical), $(I fatal), and $(I off).If a log function with `LogLevel.fatal` is called the shutdown handler ofthat logger is called.Lines 1–500 of 3071. Load more
// Written in the D programming language. /** Source: $(PHOBOSSRC std/logger/core.d) */ module std.logger.core; import core.atomic : atomicLoad, atomicOp, atomicStore, MemoryOrder; import core.sync.mutex : Mutex; import std.datetime.date : DateTime; import std.datetime.systime : Clock, SysTime; import std.range.primitives; import std.traits; import std.logger.filelogger; /+ Don’t forget to update the documentation of `std.logger` (`package.d`) when changing this test. This is a copy of example code found in its doc comment. +/ @system unittest { assert(globalLogLevel == LogLevel.all); assert((cast() sharedLog).logLevel == LogLevel.info); } /** 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 */ bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, LogLevel globalLL, lazy bool condition = true) @safe { return ll >= globalLL && ll >= loggerLL && ll != LogLevel.off && globalLL != LogLevel.off && loggerLL != LogLevel.off && condition; } /* This function formates a `SysTime` into an `OutputRange`. The `SysTime` is formatted similar to $(LREF std.datatime.DateTime.toISOExtString) except the fractional second part. The fractional second part is in milliseconds and is always 3 digits. */ void systimeToISOString(OutputRange)(OutputRange o, const ref SysTime time) if (isOutputRange!(OutputRange,string)) { import std.format.write : formattedWrite; const auto dt = cast(DateTime) time; const auto fsec = time.fracSecs.total!"msecs"; formattedWrite(o, "%04d-%02d-%02dT%02d:%02d:%02d.%03d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, fsec); } /** 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`. Params: ll = The `LogLevel` used by this log call. condition = The condition must be `true` for the data to be logged. args = The 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 bool condition, lazy A args) if (args.length != 1) { stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (ll, condition, args); } /// Ditto 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__) { stdThreadLocalLog.log!(T,moduleName)(ll, condition, arg, line, file, funcName, prettyFuncName); } /** 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`. Params: ll = The `LogLevel` used by this log call. args = The 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...)(const LogLevel ll, lazy A args) if (args.length > 1 && !is(Unqual!(A[0]) : bool)) { stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (ll, args); } /// Ditto 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__) { stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName, moduleName); } /** 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`. Params: condition = The condition must be `true` for the data to be logged. args = The 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 bool condition, lazy A args) if (args.length != 1) { stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, condition, args); } /// Ditto 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__) { stdThreadLocalLog.log!(T,moduleName)(stdThreadLocalLog.logLevel, condition, arg, line, file, funcName, prettyFuncName); } /** 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`. Params: args = The data that should be logged. Example: -------------------- log("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) if ((args.length > 1 && !is(Unqual!(A[0]) : bool) && !is(Unqual!(A[0]) == LogLevel)) || args.length == 0) { stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args); } void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string moduleName = __MODULE__) { stdThreadLocalLog.log!T(stdThreadLocalLog.logLevel, arg, line, file, funcName, prettyFuncName, moduleName); } /** 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`. Params: ll = The `LogLevel` used by this log call. 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: -------------------- 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 bool condition, lazy string msg, lazy A args) { stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (ll, condition, msg, args); } /** 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`. Params: ll = The `LogLevel` used by this log call. msg = The `printf`-style string. args = The 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...)(const LogLevel ll, lazy string msg, lazy A args) { stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (ll, msg, args); } /** 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`. 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: -------------------- 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 bool condition, lazy string msg, lazy A args) { stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, condition, msg, args); } /** 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`. Params: msg = The `printf`-style string. args = The data that should be logged. Example: -------------------- logf("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) { stdThreadLocalLog.logf!(line, file, funcName,prettyFuncName, moduleName) (stdThreadLocalLog.logLevel, msg, args); } /** 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. */ template defaultLogFunction(LogLevel ll) { 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) { stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(args); } 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) { stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, prettyFuncName, moduleName)(condition, args); } } /** 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`. Params: condition = The condition must be `true` for the data to be logged. 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"); -------------------- */ alias trace = defaultLogFunction!(LogLevel.trace); /// Ditto alias info = defaultLogFunction!(LogLevel.info); /// Ditto alias warning = defaultLogFunction!(LogLevel.warning); /// Ditto alias error = defaultLogFunction!(LogLevel.error); /// Ditto alias critical = defaultLogFunction!(LogLevel.critical); /// Ditto alias fatal = defaultLogFunction!(LogLevel.fatal); /** 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. */ template defaultLogFunctionf(LogLevel ll) { 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) { stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(msg, 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) { stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, prettyFuncName, moduleName)(condition, msg, args); } } /** 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`. Params: msg = The `printf`-style string. 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 the `sharedLog` in a $(D 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); -------------------- */ alias tracef = defaultLogFunctionf!(LogLevel.trace); /// Ditto alias infof = defaultLogFunctionf!(LogLevel.info); /// Ditto alias warningf = defaultLogFunctionf!(LogLevel.warning); /// Ditto alias errorf = defaultLogFunctionf!(LogLevel.error); /// Ditto alias criticalf = defaultLogFunctionf!(LogLevel.critical); /// Ditto alias fatalf = defaultLogFunctionf!(LogLevel.fatal); private struct MsgRange { import std.traits : isSomeString, isSomeChar; private Logger log; this(Logger log) @safe { this.log = log; } void put(T)(T msg) @safe if (isSomeString!T) { log.logMsgPart(msg); } void put(dchar elem) @safe { import std.utf : encode; char[4] buffer; size_t len = encode(buffer, elem); log.logMsgPart(buffer[0 .. len]); } } private void formatString(A...)(MsgRange oRange, A args) { import std.format.write : formattedWrite; foreach (arg; args) { formattedWrite(oRange, "%s", arg); } } @system unittest { void dummy() @safe { auto tl = new TestLogger(); auto dst = MsgRange(tl); formatString(dst, "aaa", "bbb"); } dummy(); } /** There are eight usable logging level. These level are $(I all), $(I trace), $(I info), $(I warning), $(I error), $(I critical), $(I fatal), and $(I off). If a log function with `LogLevel.fatal` is called the shutdown handler of that logger is called.