From a1d292027a299c49fc48b634b80e6afd64962a18 Mon Sep 17 00:00:00 2001 From: arossert Date: Mon, 24 Jul 2017 10:09:43 +0300 Subject: [PATCH] Add another "tweak" to enable `printf` formatting --- include/spdlog/details/logger_impl.h | 6 +++++- include/spdlog/tweakme.h | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 79c4ef69..763173c7 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -67,7 +67,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar try { details::log_msg log_msg(&_name, lvl); - log_msg.raw.write(fmt, args...); +#ifdef SPDLOG_PRINTF_FORMATTING + log_msg.raw << fmt::sprintf(fmt, args...); +#else + log_msg.raw.write(fmt, args...); +#endif _sink_it(log_msg); } catch (const std::exception &ex) diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 53f5cf7e..003484de 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -138,4 +138,14 @@ // // #define SPDLOG_LEVEL_NAMES { " TRACE", " DEBUG", " INFO", // " WARNING", " ERROR", "CRITICAL", "OFF" }; -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to use printf formatting: +// logger->log("Message %d: Hello %s", 1, "world") +// +// Otherwise use the python formatting: +// logger->log("Message {}: Hello {}", 1, "world") +// +// #define SPDLOG_PRINTF_FORMATTING +///////////////////////////////////////////////////////////////////////////////