From 7a9781a94cb1ab5878fa1a0e91e58f8c28d75134 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 2 Dec 2014 02:16:09 +0200 Subject: [PATCH] throw spdlog_err on format errors --- include/spdlog/details/pattern_formatter_impl.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index e7561608..6a0c4ee9 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -460,7 +460,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) { switch (flag) { - // logger name + // logger name case 'n': _formatters.push_back(std::unique_ptr(new details::name_formatter())); break; @@ -574,10 +574,17 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) inline void spdlog::pattern_formatter::format(details::log_msg& msg) { - for (auto &f : _formatters) + try { - f->format(msg); + for (auto &f : _formatters) + { + f->format(msg); + } + //write eol + msg.formatted.write(details::os::eol(), details::os::eol_size()); + } + catch(const fmt::FormatError& e) + { + throw spdlog_ex(fmt::format("formatting error while processing format string: {}", e.what())); } - //write eol - msg.formatted.write(details::os::eol(), details::os::eol_size()); }