File indexing completed on 2024-11-16 09:57:20
0001
0002
0003
0004 #pragma once
0005
0006 #ifndef SPDLOG_HEADER_ONLY
0007 # include <spdlog/common.h>
0008 #endif
0009
0010 #include <algorithm>
0011 #include <iterator>
0012
0013 namespace spdlog {
0014 namespace level {
0015
0016 #if __cplusplus >= 201703L
0017 constexpr
0018 #endif
0019 static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
0020
0021 static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
0022
0023 SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
0024 {
0025 return level_string_views[l];
0026 }
0027
0028 SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
0029 {
0030 return short_level_names[l];
0031 }
0032
0033 SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
0034 {
0035 auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
0036 if (it != std::end(level_string_views))
0037 return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it));
0038
0039
0040 if (name == "warn")
0041 {
0042 return level::warn;
0043 }
0044 if (name == "err")
0045 {
0046 return level::err;
0047 }
0048 return level::off;
0049 }
0050 }
0051
0052 SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
0053 : msg_(std::move(msg))
0054 {}
0055
0056 SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
0057 {
0058 #ifdef SPDLOG_USE_STD_FORMAT
0059 msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
0060 #else
0061 memory_buf_t outbuf;
0062 fmt::format_system_error(outbuf, last_errno, msg.c_str());
0063 msg_ = fmt::to_string(outbuf);
0064 #endif
0065 }
0066
0067 SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT
0068 {
0069 return msg_.c_str();
0070 }
0071
0072 SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
0073 {
0074 SPDLOG_THROW(spdlog_ex(msg, last_errno));
0075 }
0076
0077 SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
0078 {
0079 SPDLOG_THROW(spdlog_ex(std::move(msg)));
0080 }
0081
0082 }