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 a1afa99
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,12 @@ 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) {
if (!getLoggers().any!(l => l.minLevel <= level))
return;

T args_copy = args;
}

foreach (l; getLoggers())
if (l.minLevel <= level) { // WARNING: TYPE SYSTEM HOLE: accessing field of shared class!
Expand All @@ -957,6 +961,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 a1afa99

Please sign in to comment.