I have the main application that uses boost log to output log to the console and library that uses spdlog to output to the console. Logs come from multiple threads. The question is how can I guarantee that the logs will not overlap each other
Asked
Active
Viewed 439 times
0
-
Use a mutex, unless the library is already thread safe. – Michael Chourdakis Aug 10 '22 at 22:12
-
Another option is to queue messages to another thread that performs all of the logging. If the queue requires protection with a mutex, this usually keeps the lock period much shorter than writing to a log file. – user4581301 Aug 10 '22 at 22:18
-
Can you reroute spdlog output to Boost.Log? If not, you will need a way to synchronize spdlog output with Boost.Log output. If spdlog doesn't offer API to do this, you will probably have to patch it. – Andrey Semashev Aug 11 '22 at 10:58