diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 46ea415d..82162284 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -23,14 +23,6 @@ #include "details/error_handler.h" #include "sinks/sink.h" -#define SPDLOG_LOGGER_CATCH(location) \ - catch (const std::exception &ex) { \ - err_handler_.handle(location, ex.what()); \ - } \ - catch (...) { \ - err_handler_.handle(location, "Unknown exception"); \ - } - namespace spdlog { class SPDLOG_API logger { @@ -185,7 +177,12 @@ private: fmt::vformat_to(std::back_inserter(buf), format_string, fmt::make_format_args(args...)); sink_it_(details::log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()))); } - SPDLOG_LOGGER_CATCH(loc) + catch (const std::exception &ex) { \ + err_handler_.handle(loc, ex.what()); \ + } \ + catch (...) { \ + err_handler_.handle(loc, "Unknown exception"); \ + } } // log the given message (if the given log level is high enough) @@ -196,7 +193,12 @@ private: try { sink->log(msg); } - SPDLOG_LOGGER_CATCH(msg.source) + catch (const std::exception &ex) { \ + err_handler_.handle(msg.source, ex.what()); \ + } \ + catch (...) { \ + err_handler_.handle(msg.source, "Unknown exception"); \ + } } } diff --git a/src/logger.cpp b/src/logger.cpp index 101af0cd..6ab1c151 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -79,7 +79,12 @@ void logger::flush_() { try { sink->flush(); } - SPDLOG_LOGGER_CATCH(source_loc{}) + catch (const std::exception &ex) { \ + err_handler_.handle(source_loc{}, ex.what()); \ + } \ + catch (...) { \ + err_handler_.handle(source_loc{}, "Unknown exception"); \ + } } }