diff --git a/include/spdlog/common.h b/include/spdlog/common.h index ddb0d28c..1542fa92 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -100,6 +100,7 @@ inline const char *to_short_c_str(spdlog::level::level_enum l) { return short_level_names[l]; } + inline spdlog::level::level_enum from_str(const std::string &name) { static std::unordered_map name_to_level = // map string->level @@ -131,35 +132,28 @@ enum class pattern_time_type // // Log exception // -class spdlog_ex : public std::runtime_error +class spdlog_ex : public std::exception { public: explicit spdlog_ex(const std::string &msg) - : runtime_error(msg) + : msg_(msg) { } + spdlog_ex(const std::string &msg, int last_errno) - : runtime_error(msg) - , last_errno_(last_errno) { + fmt::memory_buffer outbuf; + fmt::format_system_error(outbuf, last_errno, msg); + msg_ = fmt::to_string(outbuf); } + const char *what() const SPDLOG_NOEXCEPT override { - if (last_errno_) - { - fmt::memory_buffer buf; - std::string msg(runtime_error::what()); - fmt::format_system_error(buf, last_errno_, msg); - return fmt::to_string(buf).c_str(); - } - else - { - return runtime_error::what(); - } + return msg_.c_str(); } private: - int last_errno_{0}; + std::string msg_; }; //