Fixed issue #797

This commit is contained in:
gabime 2018-08-15 19:01:44 +03:00
parent 4a871b9792
commit b962fbb15c
1 changed files with 10 additions and 16 deletions

View File

@ -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<std::string, level_enum> 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_;
};
//