Skip to content

Commit

Permalink
Fix lazy evaluation of log arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Apr 16, 2024
1 parent 18ef7c0 commit 6d4eda7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,11 @@ private void doLog(S, T...)(LogLevel level, string mod, string func, string file
nothrow
{
try {
static if(T.length != 0)
auto args_copy = args;
static if(T.length != 0) {
T args_copy;
if (getLoggers().any!(l => l.minLevel <= level))
args_copy = args;
}

foreach (l; getLoggers())
if (l.minLevel <= level) { // WARNING: TYPE SYSTEM HOLE: accessing field of shared class!
Expand All @@ -957,6 +960,13 @@ private void doLog(S, T...)(LogLevel level, string mod, string func, string file
} catch(Exception e) debug assert(false, e.msg);
}

unittest { // ensure arguments are evaluated lazily
int i = 0;
setLogLevel(LogLevel.info);
logDebug("not visible: %s", i++);
assert(i == 0);
}

private struct LogOutputRange {
LogLine info;
ScopedLock!Logger* logger;
Expand Down

0 comments on commit 6d4eda7

Please sign in to comment.