29 #ifndef INCLUDED_GR_LOGGER_H 30 #define INCLUDED_GR_LOGGER_H 39 #ifdef EXT_ENABLE_GR_LOG 40 #undef EXT_ENABLE_GR_LOG 43 #define EXT_ENABLE_GR_LOG 52 #if defined(EXT_ENABLE_GR_LOG) && !defined(ENABLE_GR_LOG) 53 #warning "Logging was requested but is not enabled in GNU Radio, so disabling." 54 #undef EXT_ENABLE_GR_LOG 59 #if !defined(EXT_ENABLE_GR_LOG) && defined(ENABLE_GR_LOG) 66 #ifdef EXT_HAVE_LOG4CPP 67 #undef EXT_HAVE_LOG4CPP 70 #define EXT_HAVE_LOG4CPP 79 #if defined(EXT_HAVE_LOG4CPP) && !defined(HAVE_LOG4CPP) 80 #warning "Log4Cpp use was requested but was not in GNU Radio, so disabling." 81 #undef EXT_HAVE_LOG4CPP 86 #if !defined(EXT_HAVE_LOG4CPP) && defined(HAVE_LOG4CPP) 93 typedef unsigned short mode_t;
95 #include <sys/types.h> 102 #include <boost/filesystem.hpp> 103 #include <boost/thread.hpp> 104 #include <boost/format.hpp> 117 #define GR_LOG_DECLARE_LOGPTR(logger) 118 #define GR_LOG_ASSIGN_LOGPTR(logger,name) 119 #define GR_CONFIG_LOGGER(config) 120 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) 121 #define GR_LOG_GETLOGGER(logger, name) 122 #define GR_SET_LEVEL(name, level) 123 #define GR_LOG_SET_LEVEL(logger, level) 124 #define GR_GET_LEVEL(name, level) 125 #define GR_LOG_GET_LEVEL(logger, level) 126 #define GR_ADD_APPENDER(name,appender) 127 #define GR_LOG_ADD_APPENDER(logger,appender) 128 #define GR_SET_APPENDER(name,appender) 129 #define GR_LOG_SET_APPENDER(logger,appender) 130 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern) 131 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern) 132 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern) 133 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern) 134 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern) 135 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern) 136 #define GR_SET_FILE_APPENDER(name,filename,append,pattern) 137 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern) 138 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern) 139 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern) 140 #define GR_GET_LOGGER_NAMES(names) 141 #define GR_RESET_CONFIGURATION() 142 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl 143 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl 144 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl 145 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl 146 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl 147 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl 148 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl 149 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl 150 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl 151 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;} 152 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);} 153 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl 154 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl 155 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl 156 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl 157 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl 158 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl 159 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl 160 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl 161 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl 162 #define GR_LOG_ERRORIF(logger, cond, msg) { \ 163 if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;} 164 #define GR_LOG_ASSERT(logger, cond, msg) { \ 165 if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};} 171 #include <log4cpp/Category.hh> 172 #include <log4cpp/PropertyConfigurator.hh> 173 #include <log4cpp/FileAppender.hh> 174 #include <log4cpp/RollingFileAppender.hh> 175 #include <log4cpp/OstreamAppender.hh> 176 #include <log4cpp/PatternLayout.hh> 202 #define GR_LOG_DECLARE_LOGPTR(logger) \ 203 gr::logger_ptr logger; 205 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \ 206 logger = gr::logger_get_logger(name); 208 #define GR_CONFIG_LOGGER(config) \ 209 gr::logger_config::load_config(config) 211 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \ 212 gr::logger_config::load_config(config,period) 214 #define GR_LOG_GETLOGGER(logger, name) \ 215 gr::logger_ptr logger = gr::logger_get_logger(name); 217 #define GR_SET_LEVEL(name, level) { \ 218 gr::logger_ptr logger = gr::logger_get_logger(name); \ 219 gr::logger_set_level(logger,level);} 221 #define GR_LOG_SET_LEVEL(logger, level) \ 222 gr::logger_set_level(logger, level); 224 #define GR_GET_LEVEL(name, level) { \ 225 gr::logger_ptr logger = gr::logger_get_logger(name); \ 226 gr::logger_get_level(logger,level);} 228 #define GR_LOG_GET_LEVEL(logger, level) \ 229 gr::logger_get_level(logger,level); 231 #define GR_ADD_APPENDER(name, appender) { \ 232 gr::logger_ptr logger = gr::logger_get_logger(name); \ 233 gr::logger_add_appender(logger,appender);} 235 #define GR_LOG_ADD_APPENDER(logger, appender) { \ 236 gr::logger_add_appender(logger, appender);} 238 #define GR_SET_APPENDER(name, appender) { \ 239 gr::logger_ptr logger = gr::logger_get_logger(name); \ 240 gr::logger_set_appender(logger,appender);} 242 #define GR_LOG_SET_APPENDER(logger, appender) { \ 243 gr::logger_set_appender(logger, appender);} 245 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) { \ 246 gr::logger_ptr logger = gr::logger_get_logger(name); \ 247 gr::logger_add_console_appender(logger,target,pattern);} 249 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \ 250 gr::logger_add_console_appender(logger,target,pattern);} 252 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) { \ 253 gr::logger_ptr logger = gr::logger_get_logger(name); \ 254 gr::logger_set_console_appender(logger,target,pattern);} 256 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) { \ 257 gr::logger_set_console_appender(logger,target,pattern);} 259 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) { \ 260 gr::logger_ptr logger = gr::logger_get_logger(name); \ 261 gr::logger_add_file_appender(logger,filename,append,pattern);} 263 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \ 264 gr::logger_add_file_appender(logger,filename,append,pattern);} 266 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) { \ 267 gr::logger_ptr logger = gr::logger_get_logger(name); \ 268 gr::logger_set_file_appender(logger,filename,append,pattern);} 270 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) { \ 271 gr::logger_set_file_appender(logger,filename,append,pattern);} 273 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \ 274 gr::logger_ptr logger = gr::logger_get_logger(name); \ 275 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);} 277 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \ 278 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);} 280 #define GR_GET_LOGGER_NAMES(names) { \ 281 names = gr::logger_get_logger_names();} 283 #define GR_RESET_CONFIGURATION() \ 284 gr::logger_config::reset_config(); 287 #define GR_DEBUG(name, msg) { \ 288 gr::logger_ptr logger = gr::logger_get_logger(name); \ 289 *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;} 291 #define GR_INFO(name, msg) { \ 292 gr::logger_ptr logger = gr::logger_get_logger(name); \ 293 *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;} 295 #define GR_NOTICE(name, msg) { \ 296 gr::logger_ptr logger = gr::logger_get_logger(name); \ 297 *logger << log4cpp::Priority::NOTICE << msg;} 299 #define GR_WARN(name, msg) { \ 300 gr::logger_ptr logger = gr::logger_get_logger(name); \ 301 *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;} 303 #define GR_ERROR(name, msg) { \ 304 gr::logger_ptr logger = gr::logger_get_logger(name); \ 305 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} 307 #define GR_CRIT(name, msg) { \ 308 gr::logger_ptr logger = gr::logger_get_logger(name); \ 309 *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;} 311 #define GR_ALERT(name, msg) { \ 312 gr::logger_ptr logger = gr::logger_get_logger(name); \ 313 *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;} 315 #define GR_FATAL(name, msg) { \ 316 gr::logger_ptr logger = gr::logger_get_logger(name); \ 317 *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;} 319 #define GR_EMERG(name, msg) { \ 320 gr::logger_ptr logger = gr::logger_get_logger(name); \ 321 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} 323 #define GR_ERRORIF(name, cond, msg) { \ 325 gr::logger_ptr logger = gr::logger_get_logger(name); \ 326 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \ 329 #define GR_ASSERT(name, cond, msg) { \ 331 gr::logger_ptr logger = gr::logger_get_logger(name); \ 332 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \ 337 #define GR_LOG_DEBUG(logger, msg) { \ 338 *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;} 340 #define GR_LOG_INFO(logger, msg) { \ 341 *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;} 343 #define GR_LOG_NOTICE(logger, msg) { \ 344 *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;} 346 #define GR_LOG_WARN(logger, msg) { \ 347 *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;} 349 #define GR_LOG_ERROR(logger, msg) { \ 350 *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;} 352 #define GR_LOG_CRIT(logger, msg) { \ 353 *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;} 355 #define GR_LOG_ALERT(logger, msg) { \ 356 *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;} 358 #define GR_LOG_FATAL(logger, msg) { \ 359 *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;} 361 #define GR_LOG_EMERG(logger, msg) { \ 362 *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;} 364 #define GR_LOG_ERRORIF(logger,cond, msg) { \ 366 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \ 369 #define GR_LOG_ASSERT(logger, cond, msg) { \ 371 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \ 386 std::string filename;
388 unsigned int watch_period;
396 static void watch_file(std::string filename,
unsigned int watch_period);
398 static bool logger_configured;
428 logger_config(logger_config
const&);
429 void operator=(logger_config
const&);
431 std::string get_filename4rpc() {
434 int get_watchperiod4rpc(){
return watch_period;};
436 std::string get_config4rpc() {
440 void set_config4rpc(std::string
set) {
441 printf(
"Set string was:%s\n",
set.c_str());
450 static logger_config& get_instance(
void);
454 static std::string get_filename();
456 static unsigned int get_watch_period();
461 static void load_config(std::string filename,
unsigned int watch_period=0);
463 static void stop_watch();
465 static void reset_config(
void);
487 GR_RUNTIME_API bool logger_load_config(
const std::string &config_filename=
"");
517 const std::string &level);
540 log4cpp::Priority::Value level);
585 log4cpp::Priority::Value &level);
596 std::string appender);
607 std::string appender);
620 std::string pattern);
633 std::string pattern);
646 std::string filename,
647 bool append, std::string pattern);
659 std::string filename,
660 bool append, std::string pattern);
676 size_t filesize,
int bkup_index,
bool append,
677 mode_t mode,std::string pattern);
686 GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(
void);
699 #define GR_LOG_DECLARE_LOGPTR(logger) 700 #define GR_LOG_ASSIGN_LOGPTR(logger,name) 701 #define GR_CONFIG_LOGGER(config) 702 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) 703 #define GR_LOG_GETLOGGER(logger, name) 704 #define GR_SET_LEVEL(name, level) 705 #define GR_LOG_SET_LEVEL(logger, level) 706 #define GR_GET_LEVEL(name, level) 707 #define GR_LOG_GET_LEVEL(logger, level) 708 #define GR_ADD_APPENDER(name,appender) 709 #define GR_LOG_ADD_APPENDER(logger,appender) 710 #define GR_SET_APPENDER(name,appender) 711 #define GR_LOG_SET_APPENDER(logger,appender) 712 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern) 713 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern) 714 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern) 715 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern) 716 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern) 717 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern) 718 #define GR_SET_FILE_APPENDER(name,filename,append,pattern) 719 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern) 720 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern) 721 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern) 722 #define GR_GET_LOGGER_NAMES(names) 723 #define GR_RESET_CONFIGURATION() 724 #define GR_DEBUG(name, msg) 725 #define GR_INFO(name, msg) 726 #define GR_NOTICE(name, msg) 727 #define GR_WARN(name, msg) 728 #define GR_ERROR(name, msg) 729 #define GR_ALERT(name, msg) 730 #define GR_CRIT(name, msg) 731 #define GR_FATAL(name, msg) 732 #define GR_EMERG(name, msg) 733 #define GR_ERRORIF(name, cond, msg) 734 #define GR_ASSERT(name, cond, msg) 735 #define GR_LOG_DEBUG(logger, msg) 736 #define GR_LOG_INFO(logger, msg) 737 #define GR_LOG_NOTICE(logger, msg) 738 #define GR_LOG_WARN(logger, msg) 739 #define GR_LOG_ERROR(logger, msg) 740 #define GR_LOG_ALERT(logger, msg) 741 #define GR_LOG_CRIT(logger, msg) 742 #define GR_LOG_FATAL(logger, msg) 743 #define GR_LOG_EMERG(logger, msg) 744 #define GR_LOG_ERRORIF(logger, cond, msg) 745 #define GR_LOG_ASSERT(logger, cond, msg) 853 int bkup_index,
bool append, mode_t mode,
854 std::string pattern) {
856 bkup_index,append,mode,pattern);
871 unsigned int watch_period = 0);
897 const std::string name);
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:719
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:852
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:781
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:737
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:739
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:741
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:799
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:738
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:705
void set_appender(std::string appender)
inline function, Method to set an appender to logger by name (define appender in conf file) ...
Definition: logger.h:827
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:721
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:808
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:715
#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:772
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:805
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:796
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:842
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:784
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:735
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:811
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:743
boost::thread thread
Definition: thread.h:47
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:717
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:790
Include this header to use the message passing features.
Definition: logger.h:695
void * logger_ptr
Definition: logger.h:696
void add_appender(std::string appender)
inline function, Method to add appender to logger by name (define appender in conf file) ...
Definition: logger.h:821
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:817
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:707
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:832
~logger()
Destructor.
Definition: logger.h:777
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:787
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:802
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:740
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:713
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:814
#define GR_LOG_SET_APPENDER(logger, appender)
Definition: logger.h:711
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:847
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:745
#define GR_LOG_ADD_APPENDER(logger, appender)
Definition: logger.h:709
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:762
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:837
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:793
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:742
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:700
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:736
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:744