Commit 1fd166d4 authored by gabime's avatar gabime

Updated example

parent 5bfeb672
...@@ -131,22 +131,22 @@ void async_example() ...@@ -131,22 +131,22 @@ void async_example()
} }
} }
// create logger with 2 targets with different log levels and formats // create logger with 2 targets with different log levels and formats
// the console will show only warnings or errors, while the file will log all
void multi_sink_example() void multi_sink_example()
{ {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt >();
console_sink->set_level(spdlog::level::warn); console_sink->set_level(spdlog::level::warn);
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt >("logs/multisink.txt", true); auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
file_sink->set_level(spdlog::level::info); file_sink->set_level(spdlog::level::trace);
spdlog::logger logger("multi_sink", {console_sink, file_sink}); spdlog::logger logger("multi_sink", {console_sink, file_sink});
logger.set_level(spdlog::level::debug);
logger.warn("this should appear in both console and file"); logger.warn("this should appear in both console and file");
logger.info("this message should not appear in the console, only in the file"); logger.info("this message should not appear in the console, only in the file");
} }
// user defined types logging by implementing operator<< // user defined types logging by implementing operator<<
#include "spdlog/fmt/ostr.h" // must be included #include "spdlog/fmt/ostr.h" // must be included
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment