Skip to content

Commit

Permalink
Ensure that loggers never yield when processing log data.
Browse files Browse the repository at this point in the history
Doing so would break fundamental assumptions about not yielding within low level code that might very well perform logging.
  • Loading branch information
s-ludwig committed Jul 27, 2024
1 parent 8b88d2d commit 781c892
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,17 @@ unittest { // ensure arguments are evaluated lazily
}

private struct LogOutputRange {
import vibe.core.core : yieldLock;

LogLine info;
ScopedLock!Logger* logger;

@safe:

this(ref ScopedLock!Logger logger, string file, int line, LogLevel level)
{
auto l = yieldLock();

() @trusted { this.logger = &logger; } ();
try {
() @trusted { this.info.time = Clock.currTime(UTC()); }(); // not @safe as of 2.065
Expand All @@ -1088,6 +1092,8 @@ private struct LogOutputRange {

void finalize()
{
auto l = yieldLock();

logger.endLine();
}

Expand All @@ -1096,6 +1102,8 @@ private struct LogOutputRange {
if (text.empty)
return;

auto l = yieldLock();

if (logger.multilineLogger) {
logger.put(text);
} else {
Expand Down

0 comments on commit 781c892

Please sign in to comment.