diff --git a/example/example.cpp b/example/example.cpp index 1c441076..b9cd9d16 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -24,12 +24,9 @@ void udp_example(); void custom_flags_example(); #include "spdlog/spdlog.h" +#include "spdlog/pattern_formatter.h" #include "spdlog/cfg/env.h" // support for loading levels from the environment variable #include "spdlog/fmt/ostr.h" // support for user defined types -#include "spdlog/pattern_formatter.h" -#include "spdlog/default_formatter.h" - -using spdlog::details::make_unique; // for pre c++14 int main(int, char *[]) { @@ -51,10 +48,9 @@ int main(int, char *[]) spdlog::debug("This message should be displayed.."); // Customize msg format for all loggers - auto formatter = make_unique("[multi_sink_example] [%^%l%$] %v"); - spdlog::set_formatter(std::move(formatter)); + spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"); spdlog::info("This an info message with custom format"); - spdlog::set_formatter(make_unique()); // back to default format + spdlog::set_pattern("%+"); // back to default format spdlog::set_level(spdlog::level::info); // Backtrace support @@ -222,14 +218,14 @@ void udp_example() my_logger->info("hello world"); } -#include // A logger with multiple sinks (stdout and file) - each with a different format and log level. void multi_sink_example() { + using spdlog::details::make_unique; // for pre c++14 auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::warn); - auto formatter = make_unique("[multi_sink_example] [%^%l%$] %v"); - console_sink->set_formatter(std::move(formatter)); + console_sink->set_formatter(make_unique("[multi_sink_example] [%^%l%$] %v")); + auto file_sink = std::make_shared("logs/multisink.txt", true); file_sink->set_level(spdlog::level::trace); @@ -305,6 +301,7 @@ public: void custom_flags_example() { + using spdlog::details::make_unique; // for pre c++14 auto formatter = make_unique(""); formatter->add_flag('*').set_pattern("[%n] [%*] [%^%l%$] %v"); spdlog::set_formatter(std::move(formatter));