mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-26 15:39:03 +08:00
Updated example
This commit is contained in:
parent
5bfeb672f7
commit
1fd166d417
@ -132,21 +132,21 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user