I am considering using XCGLogger
to replace CocoaLumberjack and would like to know if is it permissible to log the following from any thread using a global logger created and setup on the main thread as per the README?
log.info("This is not a valid format: \(inputStr)")
TL;DR: Yes, XCGLogger
is thread safe, but it uses println()
which itself it's thread safe, so other callers of println()
can make it appear as if XCGLogger
itself isn't.
XCGLogger
uses a queue to ensure all println()
it calls are called and completed in a thread safe manner.
Note however that if you call println()
directly from elsewhere in your app, or another library does, those calls are not thread safe and could still interfere with the calls from XCGLogger
.
There's a unit test in the project (testMultiThreaded
) that shows multiple calls to XCGLogger
through a concurrent queue and they all write safely. But you can see that Xcode itself outputs information about the tests as they're running and that output can become tangled with the log output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With