29 #ifndef INCLUDED_GR_LOGGER_H
30 #define INCLUDED_GR_LOGGER_H
46 typedef unsigned short mode_t;
53 #include <boost/filesystem.hpp>
54 #include <boost/thread.hpp>
55 #include <boost/format.hpp>
68 #define GR_LOG_DECLARE_LOGPTR(logger)
69 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
70 #define GR_CONFIG_LOGGER(config)
71 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
72 #define GR_LOG_GETLOGGER(logger, name)
73 #define GR_SET_LEVEL(name, level)
74 #define GR_LOG_SET_LEVEL(logger, level)
75 #define GR_GET_LEVEL(name, level)
76 #define GR_LOG_GET_LEVEL(logger, level)
77 #define GR_ADD_APPENDER(name,appender)
78 #define GR_LOG_ADD_APPENDER(logger,appender)
79 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
80 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
81 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
82 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
83 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
84 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
85 #define GR_GET_LOGGER_NAMES(names)
86 #define GR_RESET_CONFIGURATION()
87 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
88 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
89 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
90 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
91 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
92 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
93 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
94 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
95 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
96 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
97 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
98 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
99 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
100 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
101 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
102 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
103 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
104 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
105 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
106 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
107 #define GR_LOG_ERRORIF(logger, cond, msg) { \
108 if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
109 #define GR_LOG_ASSERT(logger, cond, msg) { \
110 if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
116 #include <log4cpp/Category.hh>
117 #include <log4cpp/PropertyConfigurator.hh>
118 #include <log4cpp/FileAppender.hh>
119 #include <log4cpp/RollingFileAppender.hh>
120 #include <log4cpp/OstreamAppender.hh>
121 #include <log4cpp/PatternLayout.hh>
147 #define GR_LOG_DECLARE_LOGPTR(logger) \
148 gr::logger_ptr logger;
150 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \
151 logger = gr::logger_get_logger(name);
153 #define GR_CONFIG_LOGGER(config) \
154 gr::logger_config::load_config(config)
156 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
157 gr::logger_config::load_config(config,period)
159 #define GR_LOG_GETLOGGER(logger, name) \
160 gr::logger_ptr logger = gr::logger_get_logger(name);
162 #define GR_SET_LEVEL(name, level) { \
163 gr::logger_ptr logger = gr::logger_get_logger(name); \
164 gr::logger_set_level(logger,level);}
166 #define GR_LOG_SET_LEVEL(logger, level) \
167 gr::logger_set_level(logger, level);
169 #define GR_GET_LEVEL(name, level) { \
170 gr::logger_ptr logger = gr::logger_get_logger(name); \
171 gr::logger_get_level(logger,level);}
173 #define GR_LOG_GET_LEVEL(logger, level) \
174 gr::logger_get_level(logger,level);
176 #define GR_ADD_APPENDER(name, appender) { \
177 gr::logger_ptr logger = gr::logger_get_logger(name); \
178 gr::logger_add_appender(logger,appender);}
180 #define GR_LOG_ADD_APPENDER(logger, appender) { \
181 gr::logger_add_appender(logger, appender);}
183 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) { \
184 gr::logger_ptr logger = gr::logger_get_logger(name); \
185 gr::logger_add_console_appender(logger,target,pattern);}
187 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \
188 gr::logger_add_console_appender(logger,target,pattern);}
190 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) { \
191 gr::logger_ptr logger = gr::logger_get_logger(name); \
192 gr::logger_add_file_appender(logger,filename,append,pattern);}
194 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \
195 gr::logger_add_file_appender(logger,filename,append,pattern);}
197 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \
198 gr::logger_ptr logger = gr::logger_get_logger(name); \
199 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
201 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \
202 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
204 #define GR_GET_LOGGER_NAMES(names) { \
205 names = gr::logger_get_logger_names();}
207 #define GR_RESET_CONFIGURATION() \
208 gr::logger_config::reset_config();
211 #define GR_DEBUG(name, msg) { \
212 gr::logger_ptr logger = gr::logger_get_logger(name); \
213 *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
215 #define GR_INFO(name, msg) { \
216 gr::logger_ptr logger = gr::logger_get_logger(name); \
217 *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
219 #define GR_NOTICE(name, msg) { \
220 gr::logger_ptr logger = gr::logger_get_logger(name); \
221 *logger << log4cpp::Priority::NOTICE << msg;}
223 #define GR_WARN(name, msg) { \
224 gr::logger_ptr logger = gr::logger_get_logger(name); \
225 *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
227 #define GR_ERROR(name, msg) { \
228 gr::logger_ptr logger = gr::logger_get_logger(name); \
229 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
231 #define GR_CRIT(name, msg) { \
232 gr::logger_ptr logger = gr::logger_get_logger(name); \
233 *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
235 #define GR_ALERT(name, msg) { \
236 gr::logger_ptr logger = gr::logger_get_logger(name); \
237 *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
239 #define GR_FATAL(name, msg) { \
240 gr::logger_ptr logger = gr::logger_get_logger(name); \
241 *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
243 #define GR_EMERG(name, msg) { \
244 gr::logger_ptr logger = gr::logger_get_logger(name); \
245 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
247 #define GR_ERRORIF(name, cond, msg) { \
249 gr::logger_ptr logger = gr::logger_get_logger(name); \
250 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
253 #define GR_ASSERT(name, cond, msg) { \
255 gr::logger_ptr logger = gr::logger_get_logger(name); \
256 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \
261 #define GR_LOG_DEBUG(logger, msg) { \
262 *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
264 #define GR_LOG_INFO(logger, msg) { \
265 *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
267 #define GR_LOG_NOTICE(logger, msg) { \
268 *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
270 #define GR_LOG_WARN(logger, msg) { \
271 *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
273 #define GR_LOG_ERROR(logger, msg) { \
274 *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
276 #define GR_LOG_CRIT(logger, msg) { \
277 *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
279 #define GR_LOG_ALERT(logger, msg) { \
280 *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
282 #define GR_LOG_FATAL(logger, msg) { \
283 *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
285 #define GR_LOG_EMERG(logger, msg) { \
286 *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
288 #define GR_LOG_ERRORIF(logger,cond, msg) { \
290 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
293 #define GR_LOG_ASSERT(logger, cond, msg) { \
295 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
310 std::string filename;
312 unsigned int watch_period;
320 static void watch_file(std::string filename,
unsigned int watch_period);
322 static bool logger_configured;
352 logger_config(logger_config
const&);
353 void operator=(logger_config
const&);
355 std::string get_filename4rpc() {
358 int get_watchperiod4rpc(){
return watch_period;};
360 std::string get_config4rpc() {
364 void set_config4rpc(std::string set) {
365 printf(
"Set string was:%s\n", set.c_str());
374 static logger_config& get_instance(
void);
378 static std::string get_filename();
380 static unsigned int get_watch_period();
385 static void load_config(std::string filename,
unsigned int watch_period=0);
387 static void stop_watch();
389 static void reset_config(
void);
411 GR_RUNTIME_API bool logger_load_config(
const std::string &config_filename=
"");
441 const std::string &level);
464 log4cpp::Priority::Value level);
509 log4cpp::Priority::Value &level);
520 std::string appender);
533 std::string pattern);
546 std::string filename,
547 bool append, std::string pattern);
563 size_t filesize,
int bkup_index,
bool append,
564 mode_t mode,std::string pattern);
573 GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(
void);
586 #define GR_LOG_DECLARE_LOGPTR(logger)
587 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
588 #define GR_CONFIG_LOGGER(config)
589 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
590 #define GR_LOG_GETLOGGER(logger, name)
591 #define GR_SET_LEVEL(name, level)
592 #define GR_LOG_SET_LEVEL(logger, level)
593 #define GR_GET_LEVEL(name, level)
594 #define GR_LOG_GET_LEVEL(logger, level)
595 #define GR_ADD_APPENDER(name,appender)
596 #define GR_LOG_ADD_APPENDER(logger,appender)
597 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
598 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
599 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
600 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
601 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
602 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
603 #define GR_GET_LOGGER_NAMES(names)
604 #define GR_RESET_CONFIGURATION()
605 #define GR_DEBUG(name, msg)
606 #define GR_INFO(name, msg)
607 #define GR_NOTICE(name, msg)
608 #define GR_WARN(name, msg)
609 #define GR_ERROR(name, msg)
610 #define GR_ALERT(name, msg)
611 #define GR_CRIT(name, msg)
612 #define GR_FATAL(name, msg)
613 #define GR_EMERG(name, msg)
614 #define GR_ERRORIF(name, cond, msg)
615 #define GR_ASSERT(name, cond, msg)
616 #define GR_LOG_DEBUG(logger, msg)
617 #define GR_LOG_INFO(logger, msg)
618 #define GR_LOG_NOTICE(logger, msg)
619 #define GR_LOG_WARN(logger, msg)
620 #define GR_LOG_ERROR(logger, msg)
621 #define GR_LOG_ALERT(logger, msg)
622 #define GR_LOG_CRIT(logger, msg)
623 #define GR_LOG_FATAL(logger, msg)
624 #define GR_LOG_EMERG(logger, msg)
625 #define GR_LOG_ERRORIF(logger, cond, msg)
626 #define GR_LOG_ASSERT(logger, cond, msg)
718 int bkup_index,
bool append, mode_t mode,
719 std::string pattern) {
721 bkup_index,append,mode,pattern);
736 unsigned int watch_period = 0);
std::string logger_ptr
Definition: logger.h:65
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:717
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:662
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:100
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:102
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:104
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:680
GR_RUNTIME_API std::vector< std::string > gr_logger_get_logger_names(void)
Function to return logger names to python.
#define GR_LOG_WARN(logger, msg)
Definition: logger.h:101
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:74
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:84
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:689
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
logger(std::string logger_name)
contructor Provide name of logger to associate with this class
Definition: logger.h:653
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:686
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:677
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:712
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:665
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:98
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:692
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:106
boost::thread thread
Definition: thread.h:45
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:82
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:671
void add_appender(std::string appender)
inline function, Method to add appender to logger by name (define appender in conf file) ...
Definition: logger.h:702
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:698
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:76
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:707
~logger()
Destructor.
Definition: logger.h:658
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:668
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:683
#define GR_LOG_ALERT(logger, msg)
Definition: logger.h:103
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:80
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:695
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:109
#define GR_LOG_ADD_APPENDER(logger, appender)
Definition: logger.h:78
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 ...
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
Logger class for referencing loggers in python. Not needed in C++ (use macros) Wraps and manipulates ...
Definition: logger.h:643
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:674
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:105
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:69
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:99
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:107