remove compile features from std.experimental.logger

Fix Iain comment

Razvan suggest changelog fix
This commit is contained in:
Robert burner Schadek 2022-06-01 15:34:34 +02:00 committed by The Dlang Bot
parent a504a5e7d6
commit 1f0ec5405f
3 changed files with 66 additions and 291 deletions

View file

@ -0,0 +1,8 @@
remove std.experimental.logger's capability to set the minimal LogLevel at compile time
Before this change std.experimental.logger had the capability to disable
logging at compile time.
It was also possible to set the minimal LogLevel at compile time.
The trade-off between gained capability, added complexity, and error-proneness
was too heavily tilted towards the second two items.
This change removes these compile time features.

View file

@ -12,56 +12,6 @@ import std.traits;
import std.experimental.logger.filelogger; import std.experimental.logger.filelogger;
/** 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.
*/
template isLoggingActiveAt(LogLevel ll)
{
version (StdLoggerDisableLogging)
{
enum isLoggingActiveAt = false;
}
else
{
static if (ll == LogLevel.trace)
{
version (StdLoggerDisableTrace) enum isLoggingActiveAt = false;
}
else static if (ll == LogLevel.info)
{
version (StdLoggerDisableInfo) enum isLoggingActiveAt = false;
}
else static if (ll == LogLevel.warning)
{
version (StdLoggerDisableWarning) enum isLoggingActiveAt = false;
}
else static if (ll == LogLevel.error)
{
version (StdLoggerDisableError) enum isLoggingActiveAt = false;
}
else static if (ll == LogLevel.critical)
{
version (StdLoggerDisableCritical) enum isLoggingActiveAt = false;
}
else static if (ll == LogLevel.fatal)
{
version (StdLoggerDisableFatal) enum isLoggingActiveAt = false;
}
// If `isLoggingActiveAt` didn't get defined above to false,
// we default it to true.
static if (!is(typeof(isLoggingActiveAt) == bool))
{
enum isLoggingActiveAt = true;
}
}
}
/// This compile-time flag is `true` if logging is not statically disabled.
enum isLoggingActive = isLoggingActiveAt!(LogLevel.all);
/** This functions is used at runtime to determine if a `LogLevel` is /** This functions is used at runtime to determine if a `LogLevel` is
active. The same previously defined version statements are used to disable active. The same previously defined version statements are used to disable
certain levels. Again the version statements are associated with a compile certain levels. Again the version statements are associated with a compile
@ -71,26 +21,6 @@ pure bool isLoggingEnabled()(LogLevel ll) @safe nothrow @nogc
bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL,
LogLevel globalLL, lazy bool condition = true) @safe LogLevel globalLL, lazy bool condition = true) @safe
{ {
switch (ll)
{
case LogLevel.trace:
version (StdLoggerDisableTrace) return false;
else break;
case LogLevel.info:
version (StdLoggerDisableInfo) return false;
else break;
case LogLevel.warning:
version (StdLoggerDisableWarning) return false;
else break;
case LogLevel.critical:
version (StdLoggerDisableCritical) return false;
else break;
case LogLevel.fatal:
version (StdLoggerDisableFatal) return false;
else break;
default: break;
}
return ll >= globalLL return ll >= globalLL
&& ll >= loggerLL && ll >= loggerLL
&& ll != LogLevel.off && ll != LogLevel.off
@ -99,66 +29,6 @@ bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL,
&& condition; && condition;
} }
/** This template returns the `LogLevel` named "logLevel" of type $(D
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 $(D
LogLevel) will be used. This parent lookup is continued until there is no
parent module. Then the moduleLogLevel is `LogLevel.all`.
*/
template moduleLogLevel(string moduleName)
if (!moduleName.length)
{
// default
enum moduleLogLevel = LogLevel.all;
}
///
@system unittest
{
static assert(moduleLogLevel!"" == LogLevel.all);
}
/// ditto
template moduleLogLevel(string moduleName)
if (moduleName.length)
{
import std.string : format;
mixin(q{
static if (__traits(compiles, {import %1$s : logLevel;}))
{
import %1$s : logLevel;
static assert(is(typeof(logLevel) : LogLevel),
"Expect 'logLevel' to be of Type 'LogLevel'.");
// don't enforce enum here
alias moduleLogLevel = logLevel;
}
else
// use logLevel of package or default
alias moduleLogLevel = moduleLogLevel!(parentOf(moduleName));
}.format(moduleName ~ "_loggerconfig"));
}
///
@system unittest
{
static assert(moduleLogLevel!"not.amodule.path" == LogLevel.all);
}
private string parentOf(string mod)
{
foreach_reverse (i, c; mod)
if (c == '.') return mod[0 .. i];
return null;
}
/* This function formates a `SysTime` into an `OutputRange`. /* This function formates a `SysTime` into an `OutputRange`.
The `SysTime` is formatted similar to The `SysTime` is formatted similar to
@ -200,14 +70,8 @@ void log(int line = __LINE__, string file = __FILE__,
lazy bool condition, lazy A args) lazy bool condition, lazy A args)
if (args.length != 1) if (args.length != 1)
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName)
(ll, condition, args); (ll, condition, args);
}
}
} }
/// Ditto /// Ditto
@ -215,14 +79,8 @@ void log(T, string moduleName = __MODULE__)(const LogLevel ll,
lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__, lazy bool condition, lazy T arg, int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__) string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__)
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.log!(T,moduleName)(ll, condition, arg, line, file, funcName, stdThreadLocalLog.log!(T,moduleName)(ll, condition, arg, line, file, funcName,
prettyFuncName); prettyFuncName);
}
}
} }
/** This function logs data. /** This function logs data.
@ -244,14 +102,8 @@ void log(int line = __LINE__, string file = __FILE__,
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args) string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
if (args.length > 1 && !is(Unqual!(A[0]) : bool)) if (args.length > 1 && !is(Unqual!(A[0]) : bool))
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName)
(ll, args); (ll, args);
}
}
} }
/// Ditto /// Ditto
@ -259,14 +111,8 @@ void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg,
int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__) string prettyFuncName = __PRETTY_FUNCTION__)
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName, stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName,
moduleName); moduleName);
}
}
} }
/** This function logs data. /** This function logs data.
@ -289,11 +135,8 @@ void log(int line = __LINE__, string file = __FILE__,
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args) string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
if (args.length != 1) if (args.length != 1)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.log!(line, file, funcName, prettyFuncName, moduleName)
(stdThreadLocalLog.logLevel, condition, args); (stdThreadLocalLog.logLevel, condition, args);
}
} }
/// Ditto /// Ditto
@ -301,11 +144,8 @@ void log(T, string moduleName = __MODULE__)(lazy bool condition, lazy T arg,
int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__, int line = __LINE__, string file = __FILE__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__) string prettyFuncName = __PRETTY_FUNCTION__)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.log!(T,moduleName)(stdThreadLocalLog.logLevel, stdThreadLocalLog.log!(T,moduleName)(stdThreadLocalLog.logLevel,
condition, arg, line, file, funcName, prettyFuncName); condition, arg, line, file, funcName, prettyFuncName);
}
} }
/** This function logs data. /** This function logs data.
@ -328,22 +168,16 @@ if ((args.length > 1 && !is(Unqual!(A[0]) : bool)
&& !is(Unqual!(A[0]) == LogLevel)) && !is(Unqual!(A[0]) == LogLevel))
|| args.length == 0) || args.length == 0)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.log!(line, file, funcName, stdThreadLocalLog.log!(line, file, funcName,
prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args); prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args);
}
} }
void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__, void log(T)(lazy T arg, int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__) string moduleName = __MODULE__)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.log!T(stdThreadLocalLog.logLevel, arg, line, file, stdThreadLocalLog.log!T(stdThreadLocalLog.logLevel, arg, line, file,
funcName, prettyFuncName, moduleName); funcName, prettyFuncName, moduleName);
}
} }
/** This function logs data in a `printf`-style manner. /** This function logs data in a `printf`-style manner.
@ -369,14 +203,8 @@ void logf(int line = __LINE__, string file = __FILE__,
string moduleName = __MODULE__, A...)(const LogLevel ll, string moduleName = __MODULE__, A...)(const LogLevel ll,
lazy bool condition, lazy string msg, lazy A args) lazy bool condition, lazy string msg, lazy A args)
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName)
(ll, condition, msg, args); (ll, condition, msg, args);
}
}
} }
/** This function logs data in a `printf`-style manner. /** This function logs data in a `printf`-style manner.
@ -400,14 +228,8 @@ void logf(int line = __LINE__, string file = __FILE__,
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy string msg, string moduleName = __MODULE__, A...)(const LogLevel ll, lazy string msg,
lazy A args) lazy A args)
{ {
static if (isLoggingActive)
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName)
(ll, msg, args); (ll, msg, args);
}
}
} }
/** This function logs data in a `printf`-style manner. /** This function logs data in a `printf`-style manner.
@ -431,11 +253,8 @@ void logf(int line = __LINE__, string file = __FILE__,
string moduleName = __MODULE__, A...)(lazy bool condition, string moduleName = __MODULE__, A...)(lazy bool condition,
lazy string msg, lazy A args) lazy string msg, lazy A args)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName) stdThreadLocalLog.logf!(line, file, funcName, prettyFuncName, moduleName)
(stdThreadLocalLog.logLevel, condition, msg, args); (stdThreadLocalLog.logLevel, condition, msg, args);
}
} }
/** This function logs data in a `printf`-style manner. /** This function logs data in a `printf`-style manner.
@ -457,11 +276,8 @@ void logf(int line = __LINE__, string file = __FILE__,
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy string msg, lazy A args) string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)
{ {
static if (isLoggingActive)
{
stdThreadLocalLog.logf!(line, file, funcName,prettyFuncName, moduleName) stdThreadLocalLog.logf!(line, file, funcName,prettyFuncName, moduleName)
(stdThreadLocalLog.logLevel, msg, args); (stdThreadLocalLog.logLevel, msg, args);
}
} }
/** This template provides the global log functions with the `LogLevel` /** This template provides the global log functions with the `LogLevel`
@ -477,25 +293,19 @@ template defaultLogFunction(LogLevel ll)
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy A args) string moduleName = __MODULE__, A...)(lazy A args)
if ((args.length > 0 && !is(Unqual!(A[0]) : bool)) || args.length == 0) if ((args.length > 0 && !is(Unqual!(A[0]) : bool)) || args.length == 0)
{
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{ {
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
prettyFuncName, moduleName)(args); prettyFuncName, moduleName)(args);
} }
}
void defaultLogFunction(int line = __LINE__, string file = __FILE__, void defaultLogFunction(int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args) string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
{
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{ {
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName, stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
prettyFuncName, moduleName)(condition, args); prettyFuncName, moduleName)(condition, args);
} }
}
} }
/** This function logs data to the `stdThreadLocalLog`, optionally depending /** This function logs data to the `stdThreadLocalLog`, optionally depending
@ -550,26 +360,20 @@ template defaultLogFunctionf(LogLevel ll)
string funcName = __FUNCTION__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy string msg, lazy A args) string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)
{
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{ {
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
prettyFuncName, moduleName)(msg, args); prettyFuncName, moduleName)(msg, args);
} }
}
void defaultLogFunctionf(int line = __LINE__, string file = __FILE__, void defaultLogFunctionf(int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy bool condition, string moduleName = __MODULE__, A...)(lazy bool condition,
lazy string msg, lazy A args) lazy string msg, lazy A args)
{
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{ {
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName, stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
prettyFuncName, moduleName)(condition, msg, args); prettyFuncName, moduleName)(condition, msg, args);
} }
}
} }
/** This function logs data to the `sharedLog` in a `printf`-style /** This function logs data to the `sharedLog` in a `printf`-style
@ -815,34 +619,25 @@ abstract class Logger
string prettyFuncName, string moduleName, LogLevel logLevel, string prettyFuncName, string moduleName, LogLevel logLevel,
Tid threadId, SysTime timestamp, Logger logger) Tid threadId, SysTime timestamp, Logger logger)
@safe @safe
{
static if (isLoggingActive)
{ {
msgAppender = appender!string(); msgAppender = appender!string();
header = LogEntry(file, line, funcName, prettyFuncName, header = LogEntry(file, line, funcName, prettyFuncName,
moduleName, logLevel, threadId, timestamp, null, logger); moduleName, logLevel, threadId, timestamp, null, logger);
} }
}
/** Logs a part of the log message. */ /** Logs a part of the log message. */
protected void logMsgPart(scope const(char)[] msg) @safe protected void logMsgPart(scope const(char)[] msg) @safe
{
static if (isLoggingActive)
{ {
msgAppender.put(msg); msgAppender.put(msg);
} }
}
/** Signals that the message has been written and no more calls to /** Signals that the message has been written and no more calls to
`logMsgPart` follow. */ `logMsgPart` follow. */
protected void finishLogMsg() @safe protected void finishLogMsg() @safe
{
static if (isLoggingActive)
{ {
header.msg = msgAppender.data; header.msg = msgAppender.data;
this.writeLogMsg(header); this.writeLogMsg(header);
} }
}
/** The `LogLevel` determines if the log call are processed or dropped /** The `LogLevel` determines if the log call are processed or dropped
by the `Logger`. In order for the log call to be processed the by the `Logger`. In order for the log call to be processed the
@ -894,8 +689,6 @@ abstract class Logger
since it is assumed that the caller already checked that. since it is assumed that the caller already checked that.
*/ */
void forwardMsg(ref LogEntry payload) @trusted void forwardMsg(ref LogEntry payload) @trusted
{
static if (isLoggingActive) synchronized (mutex)
{ {
if (isLoggingEnabled(payload.logLevel, this.logLevel_, if (isLoggingEnabled(payload.logLevel, this.logLevel_,
globalLogLevel)) globalLogLevel))
@ -906,7 +699,6 @@ abstract class Logger
this.fatalHandler_(); this.fatalHandler_();
} }
} }
}
/** This template provides the log functions for the `Logger` `class` /** This template provides the log functions for the `Logger` `class`
with the `LogLevel` encoded in the function name. with the `LogLevel` encoded in the function name.
@ -944,7 +736,6 @@ abstract class Logger
string moduleName = __MODULE__, A...)(lazy A args) string moduleName = __MODULE__, A...)(lazy A args)
if (args.length == 0 || (args.length > 0 && !is(A[0] : bool))) if (args.length == 0 || (args.length > 0 && !is(A[0] : bool)))
{ {
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel)) if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel))
@ -991,7 +782,6 @@ abstract class Logger
string moduleName = __MODULE__, A...)(lazy bool condition, string moduleName = __MODULE__, A...)(lazy bool condition,
lazy A args) lazy A args)
{ {
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel, if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel,
@ -1040,7 +830,6 @@ abstract class Logger
string moduleName = __MODULE__, A...)(lazy bool condition, string moduleName = __MODULE__, A...)(lazy bool condition,
lazy string msg, lazy A args) lazy string msg, lazy A args)
{ {
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;
@ -1088,7 +877,6 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy string msg, lazy A args) string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)
{ {
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;
@ -1161,7 +949,7 @@ abstract class Logger
lazy bool condition, lazy A args) lazy bool condition, lazy A args)
if (args.length != 1) if (args.length != 1)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel, condition)) if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel, condition))
{ {
@ -1185,10 +973,9 @@ abstract class Logger
string file = __FILE__, string funcName = __FUNCTION__, string file = __FILE__, string funcName = __FUNCTION__,
string prettyFuncName = __PRETTY_FUNCTION__) string prettyFuncName = __PRETTY_FUNCTION__)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel, if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel, condition))
condition) && ll >= moduleLogLevel!moduleName)
{ {
this.beginLogMsg(file, line, funcName, prettyFuncName, this.beginLogMsg(file, line, funcName, prettyFuncName,
moduleName, ll, thisTid, Clock.currTime, this); moduleName, ll, thisTid, Clock.currTime, this);
@ -1230,7 +1017,7 @@ abstract class Logger
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args) string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
if ((args.length > 1 && !is(Unqual!(A[0]) : bool)) || args.length == 0) if ((args.length > 1 && !is(Unqual!(A[0]) : bool)) || args.length == 0)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel)) if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel))
{ {
@ -1254,7 +1041,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__) string moduleName = __MODULE__)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel)) if (isLoggingEnabled(ll, this.logLevel_, globalLogLevel))
{ {
@ -1299,7 +1086,7 @@ abstract class Logger
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args) string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
if (args.length != 1) if (args.length != 1)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(this.logLevel_, this.logLevel_, if (isLoggingEnabled(this.logLevel_, this.logLevel_,
globalLogLevel, condition)) globalLogLevel, condition))
@ -1324,7 +1111,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__) string moduleName = __MODULE__)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(this.logLevel_, this.logLevel_, globalLogLevel, if (isLoggingEnabled(this.logLevel_, this.logLevel_, globalLogLevel,
condition)) condition))
@ -1371,7 +1158,7 @@ abstract class Logger
&& !is(immutable A[0] == immutable LogLevel)) && !is(immutable A[0] == immutable LogLevel))
|| args.length == 0) || args.length == 0)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(this.logLevel_, this.logLevel_, if (isLoggingEnabled(this.logLevel_, this.logLevel_,
globalLogLevel)) globalLogLevel))
@ -1395,7 +1182,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__) string moduleName = __MODULE__)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
if (isLoggingEnabled(this.logLevel_, this.logLevel_, globalLogLevel)) if (isLoggingEnabled(this.logLevel_, this.logLevel_, globalLogLevel))
{ {
@ -1442,7 +1229,7 @@ abstract class Logger
string moduleName = __MODULE__, A...)(const LogLevel ll, string moduleName = __MODULE__, A...)(const LogLevel ll,
lazy bool condition, lazy string msg, lazy A args) lazy bool condition, lazy string msg, lazy A args)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;
@ -1490,7 +1277,7 @@ abstract class Logger
string moduleName = __MODULE__, A...)(const LogLevel ll, string moduleName = __MODULE__, A...)(const LogLevel ll,
lazy string msg, lazy A args) lazy string msg, lazy A args)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;
@ -1539,7 +1326,7 @@ abstract class Logger
string moduleName = __MODULE__, A...)(lazy bool condition, string moduleName = __MODULE__, A...)(lazy bool condition,
lazy string msg, lazy A args) lazy string msg, lazy A args)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;
@ -1585,7 +1372,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy string msg, lazy A args) string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)
{ {
static if (isLoggingActive) synchronized (mutex) synchronized (mutex)
{ {
import std.format.write : formattedWrite; import std.format.write : formattedWrite;

View file

@ -146,26 +146,6 @@ To gain more precise control over the logging process, additionally to
overriding the `writeLogMsg` method the methods `beginLogMsg`, overriding the `writeLogMsg` method the methods `beginLogMsg`,
`logMsgPart` and `finishLogMsg` can be overridden. `logMsgPart` and `finishLogMsg` can be overridden.
$(H3 Compile Time Disabling of `Logger`)
In order to disable logging at compile time, pass `StdLoggerDisableLogging` as a
version argument to the `D` compiler when compiling your program code.
This will disable all logging functionality.
Specific `LogLevel` can be disabled at compile time as well.
In order to disable logging with the `trace` `LogLevel` pass
`StdLoggerDisableTrace` as a version.
The following table shows which version statement disables which
`LogLevel`.
$(TABLE
$(TR $(TD `LogLevel.trace` ) $(TD StdLoggerDisableTrace))
$(TR $(TD `LogLevel.info` ) $(TD StdLoggerDisableInfo))
$(TR $(TD `LogLevel.warning` ) $(TD StdLoggerDisableWarning))
$(TR $(TD `LogLevel.error` ) $(TD StdLoggerDisableError))
$(TR $(TD `LogLevel.critical` ) $(TD StdLoggerDisableCritical))
$(TR $(TD `LogLevel.fatal` ) $(TD StdLoggerDisableFatal))
)
Such a version statement will only disable logging in the associated compile
unit.
$(H3 Provided Logger) $(H3 Provided Logger)
By default four `Logger` implementations are given. The `FileLogger` By default four `Logger` implementations are given. The `FileLogger`
logs data to files. It can also be used to log to `stdout` and `stderr` logs data to files. It can also be used to log to `stdout` and `stderr`