Skip to content

set_pattern() for different loggers with the same sink #1902

Answered by tt4g
amirych asked this question in Q&A
Discussion options

You must be logged in to vote

The formatter is an attribute of the sink, not the logger.

spdlog::logger::set_pattern is a short hand to set the formatter for each sink in the logger.

// set formatting for the sinks in this logger.
// each sink will get a separate instance of the formatter object.
SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f)
{
for (auto it = sinks_.begin(); it != sinks_.end(); ++it)
{
if (std::next(it) == sinks_.end())
{
// last element - we can be move it.
(*it)->set_formatter(std::move(f));
break; // to prevent clang-tidy warning
}
else
{

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amirych
Comment options

Answer selected by amirych
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants