spdlog
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 {
14namespace level {
15
16#if __cplusplus >= 201703L
17constexpr
18#endif
19 static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
20
21static 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
57{
58 memory_buf_t outbuf;
59 fmt::format_system_error(outbuf, last_errno, msg.c_str());
60 msg_ = fmt::to_string(outbuf);
61}
62
64{
65 return msg_.c_str();
66}
67
68SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
69{
70 SPDLOG_THROW(spdlog_ex(msg, last_errno));
71}
72
74{
75 SPDLOG_THROW(spdlog_ex(std::move(msg)));
76}
77
78} // namespace spdlog
T begin(T... args)
T c_str(T... args)
const char * what() const SPDLOG_NOEXCEPT override
Definition common-inl.h:63
spdlog_ex(std::string msg)
Definition common-inl.h:52
std::string msg_
Definition common.h:234
#define SPDLOG_NOEXCEPT
Definition common.h:53
#define SPDLOG_INLINE
Definition common.h:33
#define SPDLOG_THROW(ex)
Definition common.h:87
T end(T... args)
T find(T... args)
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES
Definition common-inl.h:21
SPDLOG_INLINE const string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition common-inl.h:23
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
Definition common-inl.h:33
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES
Definition common-inl.h:19
SPDLOG_INLINE const char * to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition common-inl.h:28
Definition async.h:25
fmt::basic_string_view< char > string_view_t
Definition common.h:114
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
Definition common-inl.h:68
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:116