12#ifndef INCLUDED_GR_LOGGER_H
13#define INCLUDED_GR_LOGGER_H
20#ifdef DISABLE_LOGGER_H
36#include <spdlog/common.h>
37#include <spdlog/fmt/fmt.h>
38#include <spdlog/fmt/ostr.h>
44#include <spdlog/spdlog.h>
46#include <spdlog/sinks/dist_sink.h>
48#include <boost/format.hpp>
75 static constexpr const char* default_pattern =
"%n :%l: %v";
79 const log_level _default_level, _debug_level;
80 std::shared_ptr<spdlog::sinks::dist_sink_mt> _default_backend, _debug_backend;
113 using underlying_logger_ptr = std::shared_ptr<spdlog::logger>;
138 const std::string&
name()
const;
142 template <
typename... Args>
143 inline void trace(
const spdlog::string_view_t&
msg,
const Args&... args)
145 d_logger->trace(
msg, args...);
149 template <
typename... Args>
150 inline void debug(
const spdlog::string_view_t&
msg,
const Args&... args)
152 d_logger->debug(
msg, args...);
156 template <
typename... Args>
157 inline void info(
const spdlog::string_view_t&
msg,
const Args&... args)
159 d_logger->info(
msg, args...);
163 template <
typename... Args>
164 inline void notice(
const spdlog::string_view_t&
msg,
const Args&... args)
166 d_logger->info(
msg, args...);
170 template <
typename... Args>
171 inline void warn(
const spdlog::string_view_t&
msg,
const Args&... args)
173 d_logger->warn(
msg, args...);
177 template <
typename... Args>
178 inline void error(
const spdlog::string_view_t&
msg,
const Args&... args)
180 d_logger->error(
msg, args...);
184 template <
typename... Args>
185 inline void crit(
const spdlog::string_view_t&
msg,
const Args&... args)
187 d_logger->critical(
msg, args...);
191 template <
typename... Args>
192 inline void alert(
const spdlog::string_view_t&
msg,
const Args&... args)
194 d_logger->critical(
msg, args...);
198 template <
typename... Args>
199 inline void fatal(
const spdlog::string_view_t&
msg,
const Args&... args)
201 d_logger->critical(
msg, args...);
205 template <
typename... Args>
206 inline void emerg(
const spdlog::string_view_t&
msg,
const Args&... args)
208 d_logger->critical(
msg, args...);
228#define GR_LOG_TRACE(log, msg) \
230 log->d_logger->trace(msg); \
233#define GR_LOG_DEBUG(log, msg) \
235 log->d_logger->debug(msg); \
238#define GR_LOG_INFO(log, msg) \
240 log->d_logger->info(msg); \
243#define GR_LOG_NOTICE(log, msg) \
245 log->d_logger->info(msg); \
249#define GR_LOG_WARN(log, msg) \
251 log->d_logger->warn(msg); \
254#define GR_LOG_ERROR(log, msg) \
256 log->d_logger->error(msg); \
259#define GR_LOG_CRIT(log, msg) \
261 log->d_logger->critical(msg); \
264#define GR_LOG_ALERT(log, msg) \
266 log->d_logger->critical(msg); \
269#define GR_LOG_FATAL(log, msg) \
271 log->d_logger->critical(msg); \
274#define GR_LOG_EMERG(log, msg) \
276 log->d_logger->critical(msg); \
281struct fmt::formatter<boost::format> : formatter<string_view> {
283 template <
typename FormatContext>
284 auto format(
const boost::format& bfmt, FormatContext& ctx)
285 ->
decltype(formatter<string_view>::format(bfmt.str(), ctx))
287 return formatter<string_view>::format(bfmt.str(), ctx);
295 typename
std::enable_if<
297 decltype(std::declval<T>().identifier()),
301 >::type > : fmt::formatter<std::string> {
302 template <
typename FormatCtx>
303 auto format(
const T& value, FormatCtx& ctx)
304 ->
decltype(fmt::formatter<std::string>::format(value.identifier(), ctx))
306 return fmt::formatter<std::string>::format(value.identifier(), ctx);
309template <
typename T,
typename Ch>
310struct formatter<
std::shared_ptr<T>, Ch> : fmt::formatter<const void *, Ch> {
311 template <
typename FormatCtx>
312 auto format(
const std::shared_ptr<T>& ptr, FormatCtx& ctx)
313 ->
decltype(fmt::formatter<const void *, Ch>::format(fmt::ptr(ptr), ctx))
315 return fmt::formatter<const void *, Ch>::format(fmt::ptr(ptr), ctx);
321 typename std::enable_if<
323 decltype(std::declval<T>().identifier()),
327 >::type > : fmt::formatter<std::string> {
328 template <
typename FormatCtx>
329 auto format(
const std::shared_ptr<T>& ptr, FormatCtx& ctx)
330 ->
decltype(fmt::formatter<std::string>::format(ptr->identifier(), ctx))
332 return fmt::formatter<std::string>::format(ptr->identifier(), ctx);
GR_LOG macros.
Definition: logger.h:109
void crit(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for CRITICAL message
Definition: logger.h:185
void set_name(const std::string &name)
void get_level(std::string &level) const
inline function, wrapper to get the logger level
void emerg(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:206
void alert(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:192
~logger()=default
Destructor.
underlying_logger_ptr d_logger
Definition: logger.h:126
void debug(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for DEBUG message
Definition: logger.h:150
void fatal(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for CRITICAL message, DEPRECATED
Definition: logger.h:199
logger(const std::string &logger_name)
constructor Provide name of logger to associate with this class
void trace(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for TRACE message
Definition: logger.h:143
const std::string & name() const
void error(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for ERROR message
Definition: logger.h:178
void set_level(const log_level level)
void set_level(const std::string &level)
inline function, wrapper to set the logger level
void notice(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for INFO message, DEPRECATED
Definition: logger.h:164
log_level get_level() const
void warn(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for WARN message
Definition: logger.h:171
const std::string get_string_level() const
void info(const spdlog::string_view_t &msg, const Args &... args)
inline function, wrapper for INFO message
Definition: logger.h:157
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
static logging & singleton()
log_level debug_level() const
get the debug logging level
Definition: logger.h:64
void add_debug_sink(const spdlog::sink_ptr &sink)
adds a debugging sink
log_level default_level() const
get the singleton
Definition: logger.h:61
#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:211
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:51