Photon 1.0.0
Loading...
Searching...
No Matches
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
13namespace spdlog
14{
15 namespace level
16 {
17
18#if __cplusplus >= 201703L
19 constexpr
20#endif
21 static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
22
23 static const char* short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
24
26 {
27 return level_string_views[l];
28 }
29
31 {
32 return short_level_names[l];
33 }
34
36 {
37 auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
38 if (it != std::end(level_string_views))
39 return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it));
40
41 // check also for "warn" and "err" before giving up..
42 if (name == "warn")
43 {
44 return level::warn;
45 }
46 if (name == "err")
47 {
48 return level::err;
49 }
50 return level::off;
51 }
52 } // namespace level
53
55 : msg_(std::move(msg))
56 {
57 }
58
59 SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string& msg, int last_errno)
60 {
61#ifdef SPDLOG_USE_STD_FORMAT
62 msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
63#else
64 memory_buf_t outbuf;
65 fmt::format_system_error(outbuf, last_errno, msg.c_str());
66 msg_ = fmt::to_string(outbuf);
67#endif
68 }
69
71 {
72 return msg_.c_str();
73 }
74
75 SPDLOG_INLINE void throw_spdlog_ex(const std::string& msg, int last_errno)
76 {
77 SPDLOG_THROW(spdlog_ex(msg, last_errno));
78 }
79
80 SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
81 {
82 SPDLOG_THROW(spdlog_ex(std::move(msg)));
83 }
84
85} // namespace spdlog
Definition common.h:298
const char * what() const SPDLOG_NOEXCEPT override
Definition common-inl.h:70
spdlog_ex(std::string msg)
Definition common-inl.h:54
std::string msg_
Definition common.h:305
#define SPDLOG_NOEXCEPT
Definition common.h:69
#define SPDLOG_INLINE
Definition common.h:47
#define SPDLOG_THROW(ex)
Definition common.h:108
#define SPDLOG_SHORT_LEVEL_NAMES
Definition common.h:262
#define SPDLOG_LEVEL_NAMES
Definition common.h:253
SPDLOG_INLINE const string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition common-inl.h:25
level_enum
Definition common.h:233
@ err
Definition common.h:238
@ warn
Definition common.h:237
@ off
Definition common.h:240
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
Definition common-inl.h:35
SPDLOG_INLINE const char * to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition common-inl.h:30
Definition async.h:26
fmt::basic_string_view< char > string_view_t
Definition common.h:172
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
Definition common-inl.h:75
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
Definition uuid.h:926