diff --git a/changelogs/3.0.1.md b/changelogs/3.0.1.md new file mode 100644 index 0000000..aa1d93e --- /dev/null +++ b/changelogs/3.0.1.md @@ -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. diff --git a/source/slf4d/default_provider/handler.d b/source/slf4d/default_provider/handler.d index cb99ee3..69ea138 100644 --- a/source/slf4d/default_provider/handler.d +++ b/source/slf4d/default_provider/handler.d @@ -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(); + } } } }