spdlog_impl.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 //
9 // Global registry functions
10 //
11 #include "opc/spdlog/spdlog.h"
15 #ifdef SPDLOG_ENABLE_SYSLOG
17 #endif
18 
19 #ifdef _WIN32
21 #else
23 #endif
24 
25 
26 #ifdef __ANDROID__
28 #endif
29 
30 #include <chrono>
31 #include <functional>
32 #include <memory>
33 #include <string>
34 
35 inline void spdlog::register_logger(std::shared_ptr<logger> logger)
36 {
37  return details::registry::instance().register_logger(logger);
38 }
39 
40 inline std::shared_ptr<spdlog::logger> spdlog::get(const std::string& name)
41 {
42  return details::registry::instance().get(name);
43 }
44 
45 inline void spdlog::drop(const std::string &name)
46 {
47  details::registry::instance().drop(name);
48 }
49 
50 // Create multi/single threaded simple file logger
51 inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool truncate)
52 {
53  return create<spdlog::sinks::simple_file_sink_mt>(logger_name, filename, truncate);
54 }
55 
56 inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool truncate)
57 {
58  return create<spdlog::sinks::simple_file_sink_st>(logger_name, filename, truncate);
59 }
60 
61 // Create multi/single threaded rotating file logger
62 inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_mt(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files)
63 {
64  return create<spdlog::sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files);
65 }
66 
67 inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_st(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files)
68 {
69  return create<spdlog::sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files);
70 }
71 
72 // Create file logger which creates new file at midnight):
73 inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_mt(const std::string& logger_name, const filename_t& filename, int hour, int minute)
74 {
75  return create<spdlog::sinks::daily_file_sink_mt>(logger_name, filename, hour, minute);
76 }
77 
78 inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_st(const std::string& logger_name, const filename_t& filename, int hour, int minute)
79 {
80  return create<spdlog::sinks::daily_file_sink_st>(logger_name, filename, hour, minute);
81 }
82 
83 
84 //
85 // stdout/stderr loggers
86 //
87 inline std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt(const std::string& logger_name)
88 {
89  return spdlog::details::registry::instance().create(logger_name, spdlog::sinks::stdout_sink_mt::instance());
90 }
91 
92 inline std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st(const std::string& logger_name)
93 {
94  return spdlog::details::registry::instance().create(logger_name, spdlog::sinks::stdout_sink_st::instance());
95 }
96 
97 inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt(const std::string& logger_name)
98 {
99  return spdlog::details::registry::instance().create(logger_name, spdlog::sinks::stderr_sink_mt::instance());
100 }
101 
102 inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st(const std::string& logger_name)
103 {
104  return spdlog::details::registry::instance().create(logger_name, spdlog::sinks::stderr_sink_st::instance());
105 }
106 
107 //
108 // stdout/stderr color loggers
109 //
110 #ifdef _WIN32
111 inline std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt(const std::string& logger_name)
112 {
113  auto sink = std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>();
114  return spdlog::details::registry::instance().create(logger_name, sink);
115 }
116 
117 inline std::shared_ptr<spdlog::logger> spdlog::stdout_color_st(const std::string& logger_name)
118 {
119  auto sink = std::make_shared<spdlog::sinks::wincolor_stdout_sink_st>();
120  return spdlog::details::registry::instance().create(logger_name, sink);
121 }
122 
123 inline std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt(const std::string& logger_name)
124 {
125  auto sink = std::make_shared<spdlog::sinks::wincolor_stderr_sink_mt>();
126  return spdlog::details::registry::instance().create(logger_name, sink);
127 }
128 
129 
130 inline std::shared_ptr<spdlog::logger> spdlog::stderr_color_st(const std::string& logger_name)
131 {
132  auto sink = std::make_shared<spdlog::sinks::wincolor_stderr_sink_st>();
133  return spdlog::details::registry::instance().create(logger_name, sink);
134 }
135 
136 #else //ansi terminal colors
137 
138 inline std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt(const std::string& logger_name)
139 {
140  auto sink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>();
141  return spdlog::details::registry::instance().create(logger_name, sink);
142 }
143 
144 inline std::shared_ptr<spdlog::logger> spdlog::stdout_color_st(const std::string& logger_name)
145 {
146  auto sink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_st>();
147  return spdlog::details::registry::instance().create(logger_name, sink);
148 }
149 
150 inline std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt(const std::string& logger_name)
151 {
152  auto sink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
153  return spdlog::details::registry::instance().create(logger_name, sink);
154 }
155 
156 inline std::shared_ptr<spdlog::logger> spdlog::stderr_color_st(const std::string& logger_name)
157 {
158  auto sink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_st>();
159  return spdlog::details::registry::instance().create(logger_name, sink);
160 }
161 #endif
162 
163 #ifdef SPDLOG_ENABLE_SYSLOG
164 // Create syslog logger
165 inline std::shared_ptr<spdlog::logger> spdlog::syslog_logger(const std::string& logger_name, const std::string& syslog_ident, int syslog_option)
166 {
167  return create<spdlog::sinks::syslog_sink>(logger_name, syslog_ident, syslog_option);
168 }
169 #endif
170 
171 #ifdef __ANDROID__
172 inline std::shared_ptr<spdlog::logger> spdlog::android_logger(const std::string& logger_name, const std::string& tag)
173 {
174  return create<spdlog::sinks::android_sink>(logger_name, tag);
175 }
176 #endif
177 
178 // Create and register a logger a single sink
179 inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, const spdlog::sink_ptr& sink)
180 {
181  return details::registry::instance().create(logger_name, sink);
182 }
183 
184 //Create logger with multiple sinks
185 
186 inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, spdlog::sinks_init_list sinks)
187 {
188  return details::registry::instance().create(logger_name, sinks);
189 }
190 
191 
192 template <typename Sink, typename... Args>
193 inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, Args... args)
194 {
195  sink_ptr sink = std::make_shared<Sink>(args...);
196  return details::registry::instance().create(logger_name, { sink });
197 }
198 
199 
200 template<class It>
201 inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
202 {
203  return details::registry::instance().create(logger_name, sinks_begin, sinks_end);
204 }
205 
206 // Create and register an async logger with a single sink
207 inline std::shared_ptr<spdlog::logger> spdlog::create_async(const std::string& logger_name, const sink_ptr& sink, size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb)
208 {
209  return details::registry::instance().create_async(logger_name, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb, sink);
210 }
211 
212 // Create and register an async logger with multiple sinks
213 inline std::shared_ptr<spdlog::logger> spdlog::create_async(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb )
214 {
215  return details::registry::instance().create_async(logger_name, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb, sinks);
216 }
217 
218 template<class It>
219 inline std::shared_ptr<spdlog::logger> spdlog::create_async(const std::string& logger_name, const It& sinks_begin, const It& sinks_end, size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb)
220 {
221  return details::registry::instance().create_async(logger_name, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb, sinks_begin, sinks_end);
222 }
223 
225 {
226  details::registry::instance().formatter(f);
227 }
228 
229 inline void spdlog::set_pattern(const std::string& format_string)
230 {
231  return details::registry::instance().set_pattern(format_string);
232 }
233 
234 inline void spdlog::set_level(level::level_enum log_level)
235 {
236  return details::registry::instance().set_level(log_level);
237 }
238 
240 {
241  return details::registry::instance().set_error_handler(handler);
242 }
243 
244 
245 inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb)
246 {
247  details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb);
248 }
249 
251 {
252  details::registry::instance().set_sync_mode();
253 }
254 
255 inline void spdlog::apply_all(std::function<void(std::shared_ptr<logger>)> fun)
256 {
257  details::registry::instance().apply_all(fun);
258 }
259 
260 inline void spdlog::drop_all()
261 {
262  details::registry::instance().drop_all();
263 }
void set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy=async_overflow_policy::block_retry, const std::function< void()> &worker_warmup_cb=nullptr, const std::chrono::milliseconds &flush_interval_ms=std::chrono::milliseconds::zero(), const std::function< void()> &worker_teardown_cb=nullptr)
Definition: spdlog_impl.h:245
void apply_all(std::function< void(std::shared_ptr< logger >)> fun)
Definition: spdlog_impl.h:255
void set_formatter(formatter_ptr f)
Definition: spdlog_impl.h:224
std::shared_ptr< spdlog::formatter > formatter_ptr
void drop(const std::string &name)
Definition: spdlog_impl.h:45
std::shared_ptr< sinks::sink > sink_ptr
void set_pattern(const std::string &format_string)
Definition: spdlog_impl.h:229
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
name
Definition: setup.py:38
void set_error_handler(log_err_handler)
Definition: spdlog_impl.h:239
std::shared_ptr< logger > get(const std::string &name)
Definition: spdlog_impl.h:40
std::shared_ptr< logger > stdout_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:138
std::shared_ptr< logger > stderr_color_st(const std::string &logger_name)
Definition: spdlog_impl.h:156
std::shared_ptr< logger > daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0)
Definition: spdlog_impl.h:78
std::shared_ptr< logger > daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0)
Definition: spdlog_impl.h:73
std::string filename_t
std::shared_ptr< logger > create(const std::string &logger_name, const sink_ptr &sink)
Definition: spdlog_impl.h:179
std::shared_ptr< logger > create_async(const std::string &logger_name, const sink_ptr &sink, size_t queue_size, const async_overflow_policy overflow_policy=async_overflow_policy::block_retry, const std::function< void()> &worker_warmup_cb=nullptr, const std::chrono::milliseconds &flush_interval_ms=std::chrono::milliseconds::zero(), const std::function< void()> &worker_teardown_cb=nullptr)
Definition: spdlog_impl.h:207
void register_logger(std::shared_ptr< logger > logger)
Definition: spdlog_impl.h:35
std::shared_ptr< logger > stderr_logger_st(const std::string &logger_name)
Definition: spdlog_impl.h:102
std::shared_ptr< logger > basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate=false)
Definition: spdlog_impl.h:56
std::shared_ptr< logger > stdout_logger_mt(const std::string &logger_name)
Definition: spdlog_impl.h:87
std::initializer_list< sink_ptr > sinks_init_list
static registry_t< Mutex > & instance()
Definition: registry.h:180
std::shared_ptr< logger > stderr_logger_mt(const std::string &logger_name)
Definition: spdlog_impl.h:97
std::shared_ptr< logger > stdout_color_st(const std::string &logger_name)
Definition: spdlog_impl.h:144
std::shared_ptr< logger > rotating_logger_mt(const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
Definition: spdlog_impl.h:62
std::function< void(const std::string &err_msg)> log_err_handler
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:150
std::shared_ptr< logger > rotating_logger_st(const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
Definition: spdlog_impl.h:67
std::shared_ptr< logger > stdout_logger_st(const std::string &logger_name)
Definition: spdlog_impl.h:92
void set_level(level::level_enum log_level)
Definition: spdlog_impl.h:234
std::shared_ptr< logger > basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate=false)
Definition: spdlog_impl.h:51
void set_sync_mode()
Definition: spdlog_impl.h:250
void drop_all()
Definition: spdlog_impl.h:260


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