spdlog.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 // spdlog main header file.
6 // see example.cpp for usage example
7 
8 #pragma once
9 
10 #define SPDLOG_VERSION "0.13.0"
11 
12 #include "opc/spdlog/tweakme.h"
13 #include "opc/spdlog/common.h"
14 #include "opc/spdlog/logger.h"
15 
16 #include <memory>
17 #include <functional>
18 #include <chrono>
19 #include <string>
20 
21 namespace spdlog
22 {
23 
24 //
25 // Return an existing logger or nullptr if a logger with such name doesn't exist.
26 // example: spdlog::get("my_logger")->info("hello {}", "world");
27 //
28 std::shared_ptr<logger> get(const std::string& name);
29 
30 
31 //
32 // Set global formatting
33 // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
34 //
35 void set_pattern(const std::string& format_string);
37 
38 //
39 // Set global logging level for
40 //
41 void set_level(level::level_enum log_level);
42 
43 //
44 // Set global error handler
45 //
47 
48 //
49 // Turn on async mode (off by default) and set the queue size for each async_logger.
50 // effective only for loggers created after this call.
51 // queue_size: size of queue (must be power of 2):
52 // Each logger will pre-allocate a dedicated queue with queue_size entries upon construction.
53 //
54 // async_overflow_policy (optional, block_retry by default):
55 // async_overflow_policy::block_retry - if queue is full, block until queue has room for the new log entry.
56 // async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows.
57 //
58 // worker_warmup_cb (optional):
59 // callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity)
60 //
61 // worker_teardown_cb (optional):
62 // callback function that will be called in worker thread upon exit
63 //
64 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);
65 
66 // Turn off async mode
67 void set_sync_mode();
68 
69 
70 //
71 // Create and register multi/single threaded basic file logger.
72 // Basic logger simply writes to given file without any limitatons or rotations.
73 //
74 std::shared_ptr<logger> basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool truncate = false);
75 std::shared_ptr<logger> basic_logger_st(const std::string& logger_name, const filename_t& filename, bool truncate = false);
76 
77 //
78 // Create and register multi/single threaded rotating file logger
79 //
80 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);
81 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);
82 
83 //
84 // Create file logger which creates new file on the given time (default in midnight):
85 //
86 std::shared_ptr<logger> daily_logger_mt(const std::string& logger_name, const filename_t& filename, int hour=0, int minute=0);
87 std::shared_ptr<logger> daily_logger_st(const std::string& logger_name, const filename_t& filename, int hour=0, int minute=0);
88 
89 //
90 // Create and register stdout/stderr loggers
91 //
92 std::shared_ptr<logger> stdout_logger_mt(const std::string& logger_name);
93 std::shared_ptr<logger> stdout_logger_st(const std::string& logger_name);
94 std::shared_ptr<logger> stderr_logger_mt(const std::string& logger_name);
95 std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
96 //
97 // Create and register colored stdout/stderr loggers
98 //
99 std::shared_ptr<logger> stdout_color_mt(const std::string& logger_name);
100 std::shared_ptr<logger> stdout_color_st(const std::string& logger_name);
101 std::shared_ptr<logger> stderr_color_mt(const std::string& logger_name);
102 std::shared_ptr<logger> stderr_color_st(const std::string& logger_name);
103 
104 
105 //
106 // Create and register a syslog logger
107 //
108 #ifdef SPDLOG_ENABLE_SYSLOG
109 std::shared_ptr<logger> syslog_logger(const std::string& logger_name, const std::string& ident = "", int syslog_option = 0);
110 #endif
111 
112 #if defined(__ANDROID__)
113 std::shared_ptr<logger> android_logger(const std::string& logger_name, const std::string& tag = "spdlog");
114 #endif
115 
116 // Create and register a logger with a single sink
117 std::shared_ptr<logger> create(const std::string& logger_name, const sink_ptr& sink);
118 
119 // Create and register a logger with multiple sinks
120 std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks);
121 template<class It>
122 std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
123 
124 
125 // Create and register a logger with templated sink type
126 // Example:
127 // spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename");
128 template <typename Sink, typename... Args>
129 std::shared_ptr<spdlog::logger> create(const std::string& logger_name, Args...);
130 
131 // Create and register an async logger with a single sink
132 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);
133 
134 // Create and register an async logger with multiple sinks
135 std::shared_ptr<logger> create_async(const std::string& logger_name, sinks_init_list sinks, 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);
136 template<class It>
137 std::shared_ptr<logger> 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 = 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);
138 
139 // Register the given logger with the given name
140 void register_logger(std::shared_ptr<logger> logger);
141 
142 // Apply a user defined function on all registered loggers
143 // Example:
144 // spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
145 void apply_all(std::function<void(std::shared_ptr<logger>)> fun);
146 
147 // Drop the reference to the given logger
148 void drop(const std::string &name);
149 
150 // Drop all references from the registry
151 void drop_all();
152 
153 
155 //
156 // Trace & Debug can be switched on/off at compile time for zero cost debug statements.
157 // Uncomment SPDLOG_DEBUG_ON/SPDLOG_TRACE_ON in teakme.h to enable.
158 // SPDLOG_TRACE(..) will also print current file and line.
159 //
160 // Example:
161 // spdlog::set_level(spdlog::level::trace);
162 // SPDLOG_TRACE(my_logger, "some trace message");
163 // SPDLOG_TRACE(my_logger, "another trace message {} {}", 1, 2);
164 // SPDLOG_DEBUG(my_logger, "some debug message {} {}", 3, 4);
165 // SPDLOG_DEBUG_IF(my_logger, true, "some debug message {} {}", 3, 4);
167 
168 #ifdef SPDLOG_TRACE_ON
169 #define SPDLOG_STR_H(x) #x
170 #define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
171 #define SPDLOG_TRACE(logger, ...) logger->trace("[" __FILE__ " line #" SPDLOG_STR_HELPER(__LINE__) "] " __VA_ARGS__)
172 #define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[" __FILE__ " line #" SPDLOG_STR_HELPER(__LINE__) "] " __VA_ARGS__)
173 #else
174 #define SPDLOG_TRACE(logger, ...)
175 #define SPDLOG_TRACE_IF(logger, flag, ...)
176 #endif
177 
178 #ifdef SPDLOG_DEBUG_ON
179 #define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
180 #define SPDLOG_DEBUG_IF(logger, flag, ...) logger->debug_if(flag, __VA_ARGS__)
181 #else
182 #define SPDLOG_DEBUG(logger, ...)
183 #define SPDLOG_DEBUG_IF(logger, flag, ...)
184 #endif
185 
186 }
187 
188 
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
f
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 > 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
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