23 #ifndef INCLUDED_GR_LOGGER_H 24 #define INCLUDED_GR_LOGGER_H 35 #include <sys/types.h> 40 #include <log4cpp/Category.hh> 41 #include <log4cpp/FileAppender.hh> 42 #include <log4cpp/OstreamAppender.hh> 43 #include <log4cpp/PatternLayout.hh> 44 #include <log4cpp/PropertyConfigurator.hh> 45 #include <log4cpp/RollingFileAppender.hh> 48 #include <boost/filesystem.hpp> 49 #include <boost/format.hpp> 50 #include <boost/thread.hpp> 76 #define GR_LOG_DECLARE_LOGPTR(logger) gr::logger_ptr logger 78 #define GR_LOG_ASSIGN_LOGPTR(logger, name) logger = gr::logger_get_logger(name) 80 #define GR_CONFIG_LOGGER(config) gr::logger_config::load_config(config) 82 #define GR_CONFIG_AND_WATCH_LOGGER(config, period) \ 83 gr::logger_config::load_config(config, period) 85 #define GR_LOG_GETLOGGER(logger, name) gr::logger_ptr logger = gr::logger_get_logger(name) 87 #define GR_SET_LEVEL(name, level) \ 89 gr::logger_ptr logger = gr::logger_get_logger(name); \ 90 gr::logger_set_level(logger, level); \ 93 #define GR_LOG_SET_LEVEL(logger, level) gr::logger_set_level(logger, level) 95 #define GR_GET_LEVEL(name, level) \ 97 gr::logger_ptr logger = gr::logger_get_logger(name); \ 98 gr::logger_get_level(logger, level); \ 101 #define GR_LOG_GET_LEVEL(logger, level) gr::logger_get_level(logger, level) 103 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) \ 105 gr::logger_ptr logger = gr::logger_get_logger(name); \ 106 gr::logger_add_console_appender(logger, target, pattern); \ 109 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) \ 111 gr::logger_add_console_appender(logger, target, pattern); \ 114 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) \ 116 gr::logger_ptr logger = gr::logger_get_logger(name); \ 117 gr::logger_set_console_appender(logger, target, pattern); \ 120 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) \ 122 gr::logger_set_console_appender(logger, target, pattern); \ 125 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) \ 127 gr::logger_ptr logger = gr::logger_get_logger(name); \ 128 gr::logger_add_file_appender(logger, filename, append, pattern); \ 131 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) \ 133 gr::logger_add_file_appender(logger, filename, append, pattern); \ 136 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) \ 138 gr::logger_ptr logger = gr::logger_get_logger(name); \ 139 gr::logger_set_file_appender(logger, filename, append, pattern); \ 142 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) \ 144 gr::logger_set_file_appender(logger, filename, append, pattern); \ 147 #define GR_ADD_ROLLINGFILE_APPENDER( \ 148 name, filename, filesize, bkup_index, append, mode, pattern) \ 150 gr::logger_ptr logger = gr::logger_get_logger(name); \ 151 gr::logger_add_rollingfile_appender( \ 152 logger, filename, filesize, bkup_index, append, mode, pattern); \ 155 #define GR_LOG_ADD_ROLLINGFILE_APPENDER( \ 156 logger, filename, filesize, bkup_index, append, mode, pattern) \ 158 gr::logger_add_rollingfile_appender( \ 159 logger, filename, filesize, bkup_index, append, mode, pattern); \ 162 #define GR_GET_LOGGER_NAMES(names) \ 164 names = gr::logger_get_logger_names(); \ 167 #define GR_RESET_CONFIGURATION() gr::logger_config::reset_config(); 170 #define GR_DEBUG(name, msg) \ 172 gr::logger_ptr logger = gr::logger_get_logger(name); \ 173 *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \ 176 #define GR_INFO(name, msg) \ 178 gr::logger_ptr logger = gr::logger_get_logger(name); \ 179 *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \ 182 #define GR_NOTICE(name, msg) \ 184 gr::logger_ptr logger = gr::logger_get_logger(name); \ 185 *logger << log4cpp::Priority::NOTICE << (msg); \ 188 #define GR_WARN(name, msg) \ 190 gr::logger_ptr logger = gr::logger_get_logger(name); \ 191 *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \ 194 #define GR_ERROR(name, msg) \ 196 gr::logger_ptr logger = gr::logger_get_logger(name); \ 197 *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \ 200 #define GR_CRIT(name, msg) \ 202 gr::logger_ptr logger = gr::logger_get_logger(name); \ 203 *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \ 206 #define GR_ALERT(name, msg) \ 208 gr::logger_ptr logger = gr::logger_get_logger(name); \ 209 *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \ 212 #define GR_FATAL(name, msg) \ 214 gr::logger_ptr logger = gr::logger_get_logger(name); \ 215 *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \ 218 #define GR_EMERG(name, msg) \ 220 gr::logger_ptr logger = gr::logger_get_logger(name); \ 221 *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \ 224 #define GR_ERRORIF(name, cond, msg) \ 227 gr::logger_ptr logger = gr::logger_get_logger(name); \ 228 *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \ 232 #define GR_ASSERT(name, cond, msg) \ 235 gr::logger_ptr logger = gr::logger_get_logger(name); \ 236 *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \ 242 #define GR_LOG_DEBUG(logger, msg) \ 244 *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \ 247 #define GR_LOG_INFO(logger, msg) \ 249 *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \ 252 #define GR_LOG_NOTICE(logger, msg) \ 254 *logger << log4cpp::Priority::NOTICE << (msg) << log4cpp::eol; \ 257 #define GR_LOG_WARN(logger, msg) \ 259 *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \ 262 #define GR_LOG_ERROR(logger, msg) \ 264 *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \ 267 #define GR_LOG_CRIT(logger, msg) \ 269 *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \ 272 #define GR_LOG_ALERT(logger, msg) \ 274 *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \ 277 #define GR_LOG_FATAL(logger, msg) \ 279 *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \ 282 #define GR_LOG_EMERG(logger, msg) \ 284 *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \ 287 #define GR_LOG_ERRORIF(logger, cond, msg) \ 290 *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \ 294 #define GR_LOG_ASSERT(logger, cond, msg) \ 297 *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \ 313 std::string filename;
316 unsigned int watch_period;
324 static void watch_file(std::string filename,
unsigned int watch_period);
326 static bool logger_configured;
359 std::string get_filename4rpc() {
return filename; }
360 int get_watchperiod4rpc() {
return watch_period; };
362 std::string get_config4rpc() {
return filename; }
364 void set_config4rpc(std::string
set) { printf(
"Set string was:%s\n",
set.c_str()); }
374 static std::string get_filename();
376 static unsigned int get_watch_period();
381 static void load_config(std::string filename,
unsigned int watch_period = 0);
383 static void stop_watch();
385 static void reset_config(
void);
559 std::string filename,
561 std::string pattern);
573 std::string filename,
575 std::string pattern);
591 std::string filename,
596 std::string pattern);
711 d_logger, filename, filesize, bkup_index, append, mode, pattern);
726 unsigned int watch_period = 0);
755 const std::string& alias);
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:142
void add_rollingfile_appender(std::string filename, size_t filesize, int bkup_index, bool append, mode_t mode, std::string pattern)
inline function, Method to add rolling file appender to logger
Definition: logger.h:703
#define GR_LOG_DECLARE_LOGPTR(logger)
Definition: logger.h:76
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:638
GR_RUNTIME_API void logger_add_appender(logger_ptr logger, std::string appender)
Add console appender to a given logger.
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:252
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:262
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:267
GR_RUNTIME_API void gr_logger_reset_config(void)
Function to reset logger configuration from python.
void error(std::string msg)
inline function, wrapper for LOG4CPP_ERROR for ERROR message
Definition: logger.h:656
GR_RUNTIME_API std::vector< std::string > gr_logger_get_logger_names(void)
Function to return logger names to python.
GR_RUNTIME_API bool update_logger_alias(const std::string &name, const std::string &alias)
#define GR_LOG_WARN(logger, msg)
Definition: logger.h:257
GR_RUNTIME_API void logger_add_rollingfile_appender(logger_ptr logger, std::string filename, size_t filesize, int bkup_index, bool append, mode_t mode, std::string pattern)
Add rolling file appender to a given logger.
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:93
GR_RUNTIME_API void logger_set_file_appender(logger_ptr logger, std::string filename, bool append, std::string pattern)
Set a file appender to a given logger. To add another file appender, use logger_add_file_appender.
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:665
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:120
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
logger(std::string logger_name)
constructor Provide name of logger to associate with this class
Definition: logger.h:631
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:662
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:653
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:691
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:641
GR_RUNTIME_API void logger_reset_config(void)
Reset logger's configuration file.
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:242
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:668
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:282
boost::thread thread
Definition: thread.h:47
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:131
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:647
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:676
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:101
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:679
~logger()
Destructor.
Definition: logger.h:634
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:644
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:659
GR_RUNTIME_API bool logger_load_config(const std::string &config_filename="")
Load logger's configuration file.
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
#define GR_LOG_ALERT(logger, msg)
Definition: logger.h:272
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:109
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:672
GR_RUNTIME_API void logger_add_console_appender(logger_ptr logger, std::string target, std::string pattern)
Add console appender to a given logger.
GR_RUNTIME_API void logger_set_level(logger_ptr logger, const std::string &level)
Set the logger's output level.
Class to control configuration of logger. This is a singleton that can launch a thread to watch a con...
Definition: logger.h:309
void set_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to set a file appender to logger
Definition: logger.h:697
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:71
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:294
GR_RUNTIME_API void gr_logger_config(const std::string config_filename, unsigned int watch_period=0)
Function to call configuration macro from python. Note: Configuration is only updated if filename or ...
Logger class for referencing loggers in python. Not needed in C++ (use macros) Wraps and manipulates ...
Definition: logger.h:620
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:685
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:650
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:277
#define GR_LOG_ADD_ROLLINGFILE_APPENDER( logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:155
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:78
GR_RUNTIME_API void logger_add_file_appender(logger_ptr logger, std::string filename, bool append, std::string pattern)
Add file appender to a given logger.
GR_RUNTIME_API void logger_set_appender(logger_ptr logger, std::string appender)
Sets a console appender to a given logger. Deletes any existing appenders and adds a new one...
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:247
GR_RUNTIME_API logger_ptr logger_get_logger(std::string name)
Retrieve a pointer to a logger by name.
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:287
GR_RUNTIME_API std::vector< std::string > logger_get_logger_names(void)
Add rolling file appender to a given logger.
GR_RUNTIME_API void logger_get_level(logger_ptr logger, std::string &level)
Get the logger's output level.
GR_RUNTIME_API void logger_set_console_appender(logger_ptr logger, std::string target, std::string pattern)
Sets a new console appender to a given logger after removing all others. Use logger_add_console_appen...