Closed cyqsimon closed 6 months ago
Yes, all loggers you mentioned to have an internal lock that prevents log messages from that same logger to interleave.
That said if you initialize multiple loggers in parallel (instead of using init
to set a single global one) you can get interleaved lines, if they write to the same file (e.g. stdout).
That's good to know. I've got no more questions.
Thank you again for the swift response.
After I call
TermLogger::init
at the start of the main thread then spin up multiple worker threads, is it safe to use the usual logging macros in these threads without additional synchronisation?In other words, is it possible for two threads to print at the same time, and instead of producing two good lines, produce two interleaved lines of garbage? (I suspect no but just want confirmation.)
And lastly, what about
SimpleLogger
andWriteLogger
? Do they behave the same?Thanks in advance.