Could I creating multiple file loggers with the difference output format with the same output file #3263
Unanswered
NiceBlueChai
asked this question in
Q&A
Replies: 1 comment
-
You can do it, just pass a sink that makes the same file the output destination to one logger: https://github.com/gabime/spdlog/wiki/2.-Creating-loggers#creating-loggers-with-multiple-sinks Note, file_sink does not lock files on write, so log messages may be mixed if log output from multiple threads. Note also that auto first_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt");
auto second_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt");
first_sink->set_pattern(...);
second_sink->set_pattern(...);
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(first_sink);
sinks.push_back(second_sink);
auto logger = std::make_shared<spdlog::logger>("name", std::begin(sinks), std::end(sinks));
// Don't call it
logger->set_pattern(...);
//register it if you need to access it globally
spdlog::register_logger(logger); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Could I creating multiple file loggers with the difference output format with the same output file
Beta Was this translation helpful? Give feedback.
All reactions