-
When using an async logger with a For example, I create a logger like so:
where Now, will logging to those two sinks take place in different threads from the thread pool? OR, will the logging take place in the same thread since they are part of the same logger? If yes, there is no point in using two or more threads for the logging. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
All sink operations use one of the threads in the thread pool. The sink passed to dist_sink can be a non-thread-safe sink (_st suffix) if it is not used in shared with other loggers. spdlog::init_thread_pool(8192, 2);
auto logger = spdlog::create_async<spdlog::sinks::dist_sink_mt>("async logger", std::vector<spdlog::sink_ptr>{file_sink, console_sink});
// file_sink does not need to be a thread-safe.
// console_sink must be thread-safe.
auto logger = spdlog::create_async<spdlog::sinks::dist_sink_mt>("other logger", console_sink); |
Beta Was this translation helpful? Give feedback.
-
What I meant is - given the instance of Now, would the writing to the In other words, which of the following would be true? OR Scenario 2 |
Beta Was this translation helpful? Give feedback.
-
Thanks! Any chance this behavior will change in the future? Would like to see multiple threads acting on the different sinks under one dist_sink. |
Beta Was this translation helpful? Give feedback.
-
If the If on the other hand, only single thread is used for the pool (which is the default in spdlog), _st can be used (provided they are not shared between multiple loggers). If in doubt just use |
Beta Was this translation helpful? Give feedback.
The behavior described in "Scenario 2."