2019-06-04 00:09:16 +03:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-11 20:06:17 +03:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
2023-09-24 20:26:32 +03:00
|
|
|
#include <spdlog/common.h>
|
2019-05-13 00:09:00 +03:00
|
|
|
|
2021-05-08 19:13:22 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <iterator>
|
|
|
|
|
|
2019-05-12 00:22:39 +03:00
|
|
|
namespace spdlog {
|
2021-01-11 11:25:27 +01:00
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
spdlog::level level_from_str(const std::string &name) noexcept
|
2019-05-12 00:22:39 +03:00
|
|
|
{
|
2023-09-23 01:48:38 +03:00
|
|
|
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
|
2021-05-08 19:13:22 -07:00
|
|
|
if (it != std::end(level_string_views))
|
2023-09-23 17:59:51 +03:00
|
|
|
return static_cast<level>(std::distance(std::begin(level_string_views), it));
|
2021-05-08 19:13:22 -07:00
|
|
|
|
2020-02-26 18:33:49 +02:00
|
|
|
// check also for "warn" and "err" before giving up..
|
|
|
|
|
if (name == "warn")
|
|
|
|
|
{
|
2023-09-23 17:59:51 +03:00
|
|
|
return spdlog::level::warn;
|
2020-02-26 18:33:49 +02:00
|
|
|
}
|
|
|
|
|
if (name == "err")
|
|
|
|
|
{
|
2023-09-23 17:59:51 +03:00
|
|
|
return level::err;
|
2020-02-26 18:33:49 +02:00
|
|
|
}
|
2023-09-23 17:59:51 +03:00
|
|
|
return level::off;
|
2019-05-12 00:22:39 +03:00
|
|
|
}
|
|
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
spdlog_ex::spdlog_ex(std::string msg)
|
2019-05-12 00:22:39 +03:00
|
|
|
: msg_(std::move(msg))
|
|
|
|
|
{}
|
|
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
2019-05-11 20:15:03 +03:00
|
|
|
{
|
2021-11-13 11:29:05 -05:00
|
|
|
#ifdef SPDLOG_USE_STD_FORMAT
|
|
|
|
|
msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
|
|
|
|
|
#else
|
2019-08-28 18:46:09 +03:00
|
|
|
memory_buf_t outbuf;
|
2021-06-24 13:22:02 +03:00
|
|
|
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
2019-05-11 20:15:03 +03:00
|
|
|
msg_ = fmt::to_string(outbuf);
|
2021-11-13 11:29:05 -05:00
|
|
|
#endif
|
2019-05-11 20:15:03 +03:00
|
|
|
}
|
|
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
const char *spdlog_ex::what() const noexcept
|
2019-05-11 20:15:03 +03:00
|
|
|
{
|
|
|
|
|
return msg_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
void throw_spdlog_ex(const std::string &msg, int last_errno)
|
2020-03-21 23:25:12 +02:00
|
|
|
{
|
2020-03-22 00:09:56 +02:00
|
|
|
SPDLOG_THROW(spdlog_ex(msg, last_errno));
|
2020-03-21 23:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-24 13:02:30 +03:00
|
|
|
void throw_spdlog_ex(std::string msg)
|
2020-03-21 23:25:12 +02:00
|
|
|
{
|
2020-03-22 00:09:56 +02:00
|
|
|
SPDLOG_THROW(spdlog_ex(std::move(msg)));
|
2020-03-21 23:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-12 00:22:39 +03:00
|
|
|
} // namespace spdlog
|