Skip to content

Commit 6fbddd4

Browse files
committed
Make logHandler print to stdout instead of stderr
For some reason, logging to `stderr` makes test execution hang on Windows when running tests in parallel – it appears that stdout and stderr are handled the same way but there must be some difference, I wasn’t able to reduce the issue. When running the sourcekit-lsp binary, stdout gets redirected to stderr, so logging printing to stdout ends up with the same result as `fputs` to `stderr`.
1 parent 213b62f commit 6fbddd4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/SKLogging/NonDarwinLogging.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ actor LogHandlerActor {
281281

282282
/// The handler that is called to log a message from `NonDarwinLogger` unless `overrideLogHandler` is set on the logger.
283283
@LogHandlerActor
284-
var logHandler: @Sendable (String) async -> Void = { fputs($0 + "\n", stderr) }
284+
var logHandler: @Sendable (String) async -> Void = { message in
285+
// Print to stdout. When using the sourcekit-lsp binary, we will have stdout redirected to stderr, so it ends up
286+
// logging to stderr. During test execution, we log to stdout, which is generally better handled than logging to
287+
// stderr by XCTest (for some reason logging to stderr will hang test execution when running tests in parallel).
288+
print(message + "\n")
289+
}
285290

286291
/// The queue on which we log messages.
287292
///

0 commit comments

Comments
 (0)