2019-06-04 05:09:16 +08:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-12 01:06:17 +08:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
#pragma once
|
2019-05-12 01:15:03 +08:00
|
|
|
|
2019-05-13 05:09:00 +08:00
|
|
|
#ifndef SPDLOG_HEADER_ONLY
|
2021-07-19 05:50:51 +08:00
|
|
|
# include <spdlog/common.h>
|
2019-05-13 05:09:00 +08:00
|
|
|
#endif
|
|
|
|
|
2021-05-09 10:13:22 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
namespace spdlog {
|
|
|
|
namespace level {
|
2021-01-11 18:25:27 +08:00
|
|
|
|
2021-05-19 07:24:44 +08:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
constexpr
|
|
|
|
#endif
|
2021-07-19 05:50:51 +08:00
|
|
|
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
|
2019-05-12 01:15:03 +08:00
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
|
|
|
|
|
2021-01-11 18:15:29 +08:00
|
|
|
SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
2019-05-12 05:22:39 +08:00
|
|
|
{
|
|
|
|
return level_string_views[l];
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
2019-05-12 01:15:03 +08:00
|
|
|
{
|
2019-05-12 05:22:39 +08:00
|
|
|
return short_level_names[l];
|
2019-05-12 01:15:03 +08:00
|
|
|
}
|
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
|
|
|
|
{
|
2021-05-09 10:13:22 +08:00
|
|
|
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
|
|
|
|
if (it != std::end(level_string_views))
|
2022-10-13 13:25:16 +08:00
|
|
|
return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it));
|
2021-05-09 10:13:22 +08:00
|
|
|
|
2020-02-27 00:33:49 +08:00
|
|
|
// check also for "warn" and "err" before giving up..
|
|
|
|
if (name == "warn")
|
|
|
|
{
|
|
|
|
return level::warn;
|
|
|
|
}
|
|
|
|
if (name == "err")
|
|
|
|
{
|
|
|
|
return level::err;
|
|
|
|
}
|
|
|
|
return level::off;
|
2019-05-12 05:22:39 +08:00
|
|
|
}
|
|
|
|
} // namespace level
|
|
|
|
|
|
|
|
SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
|
|
|
|
: msg_(std::move(msg))
|
|
|
|
{}
|
|
|
|
|
|
|
|
SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
2019-05-12 01:15:03 +08:00
|
|
|
{
|
2021-11-14 00:29:05 +08:00
|
|
|
#ifdef SPDLOG_USE_STD_FORMAT
|
|
|
|
msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
|
|
|
|
#else
|
2019-08-28 23:46:09 +08:00
|
|
|
memory_buf_t outbuf;
|
2021-06-24 18:22:02 +08:00
|
|
|
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
2019-05-12 01:15:03 +08:00
|
|
|
msg_ = fmt::to_string(outbuf);
|
2021-11-14 00:29:05 +08:00
|
|
|
#endif
|
2019-05-12 01:15:03 +08:00
|
|
|
}
|
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT
|
2019-05-12 01:15:03 +08:00
|
|
|
{
|
|
|
|
return msg_.c_str();
|
|
|
|
}
|
|
|
|
|
2020-03-22 05:25:12 +08:00
|
|
|
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
|
|
|
|
{
|
2020-03-22 06:09:56 +08:00
|
|
|
SPDLOG_THROW(spdlog_ex(msg, last_errno));
|
2020-03-22 05:25:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
|
|
|
|
{
|
2020-03-22 06:09:56 +08:00
|
|
|
SPDLOG_THROW(spdlog_ex(std::move(msg)));
|
2020-03-22 05:25:12 +08:00
|
|
|
}
|
|
|
|
|
2019-05-12 05:22:39 +08:00
|
|
|
} // namespace spdlog
|