Skip to content

Commit

Permalink
Merge pull request #399 from vibe-d/fix_lazy_log_evaluation
Browse files Browse the repository at this point in the history
Fix lazy evaluation of log arguments
  • Loading branch information
s-ludwig authored Apr 18, 2024
2 parents 18ef7c0 + a1afa99 commit e99d0e3
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 e99d0e3

Please sign in to comment.