Skip to content

Commit

Permalink
Synchronized DefaultLogHandler writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlalis committed Apr 3, 2024
1 parent 1d09eb3 commit e52d411
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions changelogs/3.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Version 3.0.1

- Added synchronization to the DefaultLogHandler to avoid interleaving messages
between the stdout and stderr streams. Each is individually synchronized by
the library/system, but both are not synchronized with respect to each other,
so errors and info messages may overwrite each other when printed into a
single source.
14 changes: 8 additions & 6 deletions source/slf4d/default_provider/handler.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class DefaultLogHandler : LogHandler {
public void handle(immutable LogMessage msg) {
import std.stdio;
string logStr = formatLogMessage(msg, this.colored);
if (msg.level.value >= Levels.ERROR.value) {
stderr.writeln(logStr);
stderr.flush();
} else {
stdout.writeln(logStr);
stdout.flush();
synchronized(this) {
if (msg.level.value >= Levels.ERROR.value) {
stderr.writeln(logStr);
stderr.flush();
} else {
stdout.writeln(logStr);
stdout.flush();
}
}
}
}
Expand Down

0 comments on commit e52d411

Please sign in to comment.