include/opc/spdlog/common.h
Go to the documentation of this file.
1 //
2 // Copyright(c) 2015 Gabi Melman.
3 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 //
5 
6 #pragma once
7 
8 #include <string>
9 #include <initializer_list>
10 #include <chrono>
11 #include <memory>
12 #include <atomic>
13 #include <exception>
14 #include<functional>
15 
16 #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
17 #include <codecvt>
18 #include <locale>
19 #endif
20 
22 
23 //visual studio upto 2013 does not support noexcept nor constexpr
24 #if defined(_MSC_VER) && (_MSC_VER < 1900)
25 #define SPDLOG_NOEXCEPT throw()
26 #define SPDLOG_CONSTEXPR
27 #else
28 #define SPDLOG_NOEXCEPT noexcept
29 #define SPDLOG_CONSTEXPR constexpr
30 #endif
31 
32 // See tweakme.h
33 #if !defined(SPDLOG_FINAL)
34 #define SPDLOG_FINAL
35 #endif
36 
37 #if defined(__GNUC__) || defined(__clang__)
38 #define SPDLOG_DEPRECATED __attribute__((deprecated))
39 #elif defined(_MSC_VER)
40 #define SPDLOG_DEPRECATED __declspec(deprecated)
41 #else
42 #define SPDLOG_DEPRECATED
43 #endif
44 
45 
46 #include "opc/spdlog/fmt/fmt.h"
47 
48 namespace spdlog
49 {
50 
51 class formatter;
52 
53 namespace sinks
54 {
55 class sink;
56 }
57 
58 using log_clock = std::chrono::system_clock;
59 using sink_ptr = std::shared_ptr < sinks::sink >;
60 using sinks_init_list = std::initializer_list < sink_ptr >;
61 using formatter_ptr = std::shared_ptr<spdlog::formatter>;
62 #if defined(SPDLOG_NO_ATOMIC_LEVELS)
64 #else
65 using level_t = std::atomic<int>;
66 #endif
67 
68 using log_err_handler = std::function<void(const std::string &err_msg)>;
69 
70 //Log level enum
71 namespace level
72 {
73 typedef enum
74 {
75  trace = 0,
76  debug = 1,
77  info = 2,
78  warn = 3,
79  err = 4,
80  critical = 5,
81  off = 6
82 } level_enum;
83 
84 #if !defined(SPDLOG_LEVEL_NAMES)
85 #define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" };
86 #endif
87 static const char* level_names[] SPDLOG_LEVEL_NAMES
88 
89 static const char* short_level_names[] { "T", "D", "I", "W", "E", "C", "O" };
90 
91 inline const char* to_str(spdlog::level::level_enum l)
92 {
93  return level_names[l];
94 }
95 
97 {
98  return short_level_names[l];
99 }
100 } //level
101 
102 
103 //
104 // Async overflow policy - block by default.
105 //
107 {
108  block_retry, // Block / yield / sleep until message can be enqueued
109  discard_log_msg // Discard the message it enqueue fails
110 };
111 
112 //
113 // Pattern time - specific time getting to use for pattern_formatter.
114 // local time by default
115 //
117 {
118  local, // log localtime
119  utc // log utc
120 };
121 
122 //
123 // Log exception
124 //
125 namespace details
126 {
127 namespace os
128 {
129 std::string errno_str(int err_num);
130 }
131 }
132 class spdlog_ex: public std::exception
133 {
134 public:
135  spdlog_ex(const std::string& msg):_msg(msg)
136  {}
137  spdlog_ex(const std::string& msg, int last_errno)
138  {
139  _msg = msg + ": " + details::os::errno_str(last_errno);
140  }
141  const char* what() const SPDLOG_NOEXCEPT override
142  {
143  return _msg.c_str();
144  }
145 private:
147 
148 };
149 
150 //
151 // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
152 //
153 #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
154 using filename_t = std::wstring;
155 #else
157 #endif
158 
159 
160 } //spdlog
static const char *level_names[] static SPDLOG_LEVEL_NAMES const char * short_level_names[]
spdlog_ex(const std::string &msg)
const char * what() const SPDLOG_NOEXCEPT override
#define SPDLOG_NOEXCEPT
std::shared_ptr< spdlog::formatter > formatter_ptr
std::shared_ptr< sinks::sink > sink_ptr
spdlog_ex(const std::string &msg, int last_errno)
std::string errno_str(int err_num)
Definition: os.h:390
const char * to_short_str(spdlog::level::level_enum l)
std::string filename_t
std::chrono::system_clock log_clock
std::initializer_list< sink_ptr > sinks_init_list
const char * to_str(spdlog::level::level_enum l)
std::atomic< int > level_t
#define SPDLOG_LEVEL_NAMES
std::function< void(const std::string &err_msg)> log_err_handler


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04