Commit 59d1d8e5 authored by gabime's avatar gabime

Fixed example

parent e83cc703
......@@ -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<spdlog::pattern_formatter>("[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<spdlog::default_formatter>()); // 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 <spdlog/pattern_formatter.h>
// 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<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn);
auto formatter = make_unique<spdlog::pattern_formatter>("[multi_sink_example] [%^%l%$] %v");
console_sink->set_formatter(std::move(formatter));
console_sink->set_formatter(make_unique<spdlog::pattern_formatter>("[multi_sink_example] [%^%l%$] %v"));
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("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<spdlog::pattern_formatter>("");
formatter->add_flag<my_formatter_flag>('*').set_pattern("[%n] [%*] [%^%l%$] %v");
spdlog::set_formatter(std::move(formatter));
......
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