Agora  1.2.0
Agora project
common-inl.h
Go to the documentation of this file.
1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
6 #ifndef SPDLOG_HEADER_ONLY
7 # include <spdlog/common.h>
8 #endif
9 
10 #include <algorithm>
11 #include <iterator>
12 
13 namespace spdlog {
14 namespace level {
15 
16 #if __cplusplus >= 201703L
17 constexpr
18 #endif
19  static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
20 
21 static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
22 
24 {
25  return level_string_views[l];
26 }
27 
29 {
30  return short_level_names[l];
31 }
32 
34 {
35  auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
36  if (it != std::end(level_string_views))
37  return static_cast<level::level_enum>(it - std::begin(level_string_views));
38 
39  // check also for "warn" and "err" before giving up..
40  if (name == "warn")
41  {
42  return level::warn;
43  }
44  if (name == "err")
45  {
46  return level::err;
47  }
48  return level::off;
49 }
50 } // namespace level
51 
53  : msg_(std::move(msg))
54 {}
55 
56 SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
57 {
58 #ifdef SPDLOG_USE_STD_FORMAT
59  msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
60 #else
61  memory_buf_t outbuf;
62  fmt::format_system_error(outbuf, last_errno, msg.c_str());
63  msg_ = fmt::to_string(outbuf);
64 #endif
65 }
66 
68 {
69  return msg_.c_str();
70 }
71 
72 SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
73 {
74  SPDLOG_THROW(spdlog_ex(msg, last_errno));
75 }
76 
77 SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
78 {
79  SPDLOG_THROW(spdlog_ex(std::move(msg)));
80 }
81 
82 } // namespace spdlog
spdlog::level::to_string_view
const SPDLOG_INLINE string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common-inl.h:23
SPDLOG_NOEXCEPT
#define SPDLOG_NOEXCEPT
Definition: common.h:64
spdlog::level::off
@ off
Definition: common.h:219
spdlog::level::warn
@ warn
Definition: common.h:216
fmt::v8::basic_string_view
Definition: core.h:448
spdlog::level::SPDLOG_LEVEL_NAMES
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES
Definition: common-inl.h:19
spdlog::level::level_enum
level_enum
Definition: common.h:211
spdlog::level::err
@ err
Definition: common.h:217
spdlog::level::from_str
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
Definition: common-inl.h:33
fmt::v8::basic_memory_buffer
Definition: format.h:677
fmt::v8::detail::find
auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2258
spdlog
Definition: async.h:25
spdlog::throw_spdlog_ex
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
Definition: common-inl.h:72
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::begin
begin_tag begin(T &&...)
spdlog::level::to_short_c_str
const SPDLOG_INLINE char * to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common-inl.h:28
spdlog::spdlog_ex::what
const char * what() const noexcept override
Definition: common-inl.h:67
fmt::v8::to_string
auto to_string(const T &value) -> std::string
Definition: format.h:2882
spdlog::spdlog_ex::msg_
std::string msg_
Definition: common.h:284
SPDLOG_INLINE
#define SPDLOG_INLINE
Definition: common.h:42
spdlog::spdlog_ex
Definition: common.h:276
SPDLOG_THROW
#define SPDLOG_THROW(ex)
Definition: common.h:103
common.h
fmt::v8::system_error
auto system_error(int error_code, format_string< T... > fmt, T &&... args) -> std::system_error
Definition: format.h:2471
std
Definition: json.hpp:5213
spdlog::spdlog_ex::spdlog_ex
spdlog_ex(std::string msg)
Definition: common-inl.h:52
l
l
Definition: parse_all_dl.m:71
fmt::v8::format_system_error
void format_system_error(detail::buffer< char > &out, int error_code, const char *message)
Definition: format-inl.h:2562
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::end
end_tag end(T &&...)
spdlog::level::SPDLOG_SHORT_LEVEL_NAMES
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES
Definition: common-inl.h:21