12 #ifndef INCLUDED_GR_LOGGER_H
13 #define INCLUDED_GR_LOGGER_H
20 #ifdef DISABLE_LOGGER_H
36 #include <spdlog/common.h>
38 #include <spdlog/fmt/fmt.h>
39 #include <spdlog/fmt/ostr.h>
40 #include <spdlog/version.h>
43 #include <spdlog/spdlog.h>
45 #include <spdlog/sinks/dist_sink.h>
47 #include <boost/format.hpp>
88 static constexpr
const char* default_pattern =
"%n :%l: %v";
92 std::shared_ptr<spdlog::sinks::dist_sink_mt> _default_backend, _debug_backend;
125 using underlying_logger_ptr = std::shared_ptr<spdlog::logger>;
127 #if SPDLOG_VERSION >= 11000
130 template <
typename... Args>
131 using format_string_t = spdlog::format_string_t<Args...>;
132 #elif SPDLOG_VERSION >= 10910
135 template <
typename... Args>
136 using format_string_t = fmt::format_string<Args...>;
139 template <
typename... Args>
140 using format_string_t =
const spdlog::string_view_t&;
170 const std::string&
name()
const;
174 template <
typename... Args>
175 inline void trace(format_string_t<Args...>
msg, Args&&... args)
177 d_logger->trace(
msg, std::forward<Args>(args)...);
181 template <
typename... Args>
182 inline void debug(format_string_t<Args...>
msg, Args&&... args)
184 d_logger->debug(
msg, std::forward<Args>(args)...);
188 template <
typename... Args>
189 inline void info(format_string_t<Args...>
msg, Args&&... args)
191 d_logger->info(
msg, std::forward<Args>(args)...);
195 template <
typename... Args>
196 inline void notice(format_string_t<Args...>
msg, Args&&... args)
198 d_logger->info(
msg, std::forward<Args>(args)...);
202 template <
typename... Args>
203 inline void warn(format_string_t<Args...>
msg, Args&&... args)
205 d_logger->warn(
msg, std::forward<Args>(args)...);
209 template <
typename... Args>
210 inline void error(format_string_t<Args...>
msg, Args&&... args)
212 d_logger->error(
msg, std::forward<Args>(args)...);
216 template <
typename... Args>
217 inline void crit(format_string_t<Args...>
msg, Args&&... args)
219 d_logger->critical(
msg, std::forward<Args>(args)...);
223 template <
typename... Args>
224 inline void alert(format_string_t<Args...>
msg, Args&&... args)
226 d_logger->critical(
msg, std::forward<Args>(args)...);
230 template <
typename... Args>
231 inline void fatal(format_string_t<Args...>
msg, Args&&... args)
233 d_logger->critical(
msg, std::forward<Args>(args)...);
237 template <
typename... Args>
238 inline void emerg(format_string_t<Args...>
msg, Args&&... args)
240 d_logger->critical(
msg, std::forward<Args>(args)...);
243 template <
typename... Args>
245 log(spdlog::level::level_enum level, format_string_t<Args...>
msg, Args&&... args)
247 d_logger->log(level,
msg, std::forward<Args>(args)...);
267 #define GR_LOG_TRACE(log, msg) \
269 log->d_logger->trace(msg); \
272 #define GR_LOG_DEBUG(log, msg) \
274 log->d_logger->debug(msg); \
277 #define GR_LOG_INFO(log, msg) \
279 log->d_logger->info(msg); \
282 #define GR_LOG_NOTICE(log, msg) \
284 log->d_logger->info(msg); \
288 #define GR_LOG_WARN(log, msg) \
290 log->d_logger->warn(msg); \
293 #define GR_LOG_ERROR(log, msg) \
295 log->d_logger->error(msg); \
298 #define GR_LOG_CRIT(log, msg) \
300 log->d_logger->critical(msg); \
303 #define GR_LOG_ALERT(log, msg) \
305 log->d_logger->critical(msg); \
308 #define GR_LOG_FATAL(log, msg) \
310 log->d_logger->critical(msg); \
313 #define GR_LOG_EMERG(log, msg) \
315 log->d_logger->critical(msg); \
320 struct fmt::formatter<boost::
format> : formatter<string_view> {
322 template <
typename FormatContext>
323 auto format(
const boost::format& bfmt, FormatContext& ctx)
324 -> decltype(formatter<string_view>::format(bfmt.str(), ctx))
326 return formatter<string_view>::format(bfmt.str(), ctx);
GR_LOG macros.
Definition: logger.h:121
void alert(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:224
void set_name(const std::string &name)
const std::string & name() const
void get_level(std::string &level) const
inline function, wrapper to get the logger level
void error(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for ERROR message
Definition: logger.h:210
void trace(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for TRACE message
Definition: logger.h:175
void log(spdlog::level::level_enum level, format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for logging with ad-hoc adjustable level
Definition: logger.h:245
~logger()=default
Destructor.
underlying_logger_ptr d_logger
Definition: logger.h:158
void crit(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for CRITICAL message
Definition: logger.h:217
void info(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for INFO message
Definition: logger.h:189
void debug(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for DEBUG message
Definition: logger.h:182
logger(const std::string &logger_name)
constructor Provide name of logger to associate with this class
void set_level(const log_level level)
void notice(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for INFO message, DEPRECATED
Definition: logger.h:196
void set_level(const std::string &level)
inline function, wrapper to set the logger level
void fatal(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:231
void emerg(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:238
log_level get_level() const
const std::string get_string_level() const
void warn(format_string_t< Args... > msg, Args &&... args)
inline function, wrapper for WARN message
Definition: logger.h:203
void set_default_level(log_level level)
set the default logging level
void add_default_sink(const spdlog::sink_ptr &sink)
adds a logging sink
spdlog::sink_ptr default_backend() const
void operator=(logging const &)=delete
void add_default_console_sink()
add a default-constructed console sink to the default logger
logging(logging const &)=delete
void add_debug_console_sink()
add a default-constructed console sink to the debugging logger
void set_debug_level(log_level level)
set the debug logging level
log_level debug_level() const
get the debug logging level
Definition: logger.h:70
static logging & singleton()
void add_debug_sink(const spdlog::sink_ptr &sink)
adds a debugging sink
log_level default_level() const
get the default logging level
Definition: logger.h:67
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GR_RUNTIME_API const pmt::pmt_t msg()
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:250
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string &name)
spdlog::level::level_enum log_level
Definition: logger.h:50
fmt::format_context::iterator format(const gr::io_signature &iosig, format_context &ctx) const