Commit 035a8ff0 authored by gabime's avatar gabime

Added logger::set_formatter template overload

parent aa14b833
......@@ -51,9 +51,9 @@ int main(int, char *[])
spdlog::debug("This message should be displayed..");
// Customize msg format
spdlog::default_logger()->set_formatter(make_unique<spdlog::pattern_formatter>("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"));
spdlog::default_logger()->set_formatter<spdlog::pattern_formatter>("[%H:%M:%S %z] [%^%L%$] [thread %t] %v");
spdlog::info("This an info message with custom format");
spdlog::default_logger()->set_formatter(make_unique<spdlog::default_formatter>()); // back to default format
spdlog::default_logger()->set_formatter<spdlog::default_formatter>(); // back to default format
spdlog::default_logger()->set_level(spdlog::level::info);
try
......@@ -285,7 +285,7 @@ public:
std::unique_ptr<custom_flag_formatter> clone() const override
{
return spdlog::details::make_unique<my_formatter_flag>();
return make_unique<my_formatter_flag>();
}
};
......
......@@ -279,6 +279,13 @@ public:
// each sink will get a separate instance of the formatter object.
void set_formatter(std::unique_ptr<formatter> f);
template<typename Formatter, typename... Args>
void set_formatter(Args &&...args)
{
set_formatter(details::make_unique<Formatter>(std::forward<Args>(args)...));
}
// flush functions
void flush();
void flush_on(level::level_enum log_level);
......
......@@ -12,7 +12,7 @@ static std::string log_to_str(const std::string &msg, const Args &... args)
spdlog::logger oss_logger("pattern_tester", oss_sink);
oss_logger.set_level(spdlog::level::info);
oss_logger.set_formatter(std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
oss_logger.set_formatter<spdlog::pattern_formatter>(args...);
oss_logger.info(msg);
return oss.str();
......
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