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_SET_APPENDER(name,appender)
80 #define GR_LOG_SET_APPENDER(logger,appender)
81 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
82 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
83 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
84 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
85 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
86 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
87 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
88 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
89 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
90 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
91 #define GR_GET_LOGGER_NAMES(names)
92 #define GR_RESET_CONFIGURATION()
93 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
94 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
95 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
96 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
97 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
98 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
99 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
100 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
101 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
102 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
103 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
104 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
105 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
106 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
107 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
108 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
109 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
110 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
111 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
112 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
113 #define GR_LOG_ERRORIF(logger, cond, msg) { \
114 if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
115 #define GR_LOG_ASSERT(logger, cond, msg) { \
116 if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
122 #include <log4cpp/Category.hh>
123 #include <log4cpp/PropertyConfigurator.hh>
124 #include <log4cpp/FileAppender.hh>
125 #include <log4cpp/RollingFileAppender.hh>
126 #include <log4cpp/OstreamAppender.hh>
127 #include <log4cpp/PatternLayout.hh>
153 #define GR_LOG_DECLARE_LOGPTR(logger) \
154 gr::logger_ptr logger;
156 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \
157 logger = gr::logger_get_logger(name);
159 #define GR_CONFIG_LOGGER(config) \
160 gr::logger_config::load_config(config)
162 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
163 gr::logger_config::load_config(config,period)
165 #define GR_LOG_GETLOGGER(logger, name) \
166 gr::logger_ptr logger = gr::logger_get_logger(name);
168 #define GR_SET_LEVEL(name, level) { \
169 gr::logger_ptr logger = gr::logger_get_logger(name); \
170 gr::logger_set_level(logger,level);}
172 #define GR_LOG_SET_LEVEL(logger, level) \
173 gr::logger_set_level(logger, level);
175 #define GR_GET_LEVEL(name, level) { \
176 gr::logger_ptr logger = gr::logger_get_logger(name); \
177 gr::logger_get_level(logger,level);}
179 #define GR_LOG_GET_LEVEL(logger, level) \
180 gr::logger_get_level(logger,level);
182 #define GR_ADD_APPENDER(name, appender) { \
183 gr::logger_ptr logger = gr::logger_get_logger(name); \
184 gr::logger_add_appender(logger,appender);}
186 #define GR_LOG_ADD_APPENDER(logger, appender) { \
187 gr::logger_add_appender(logger, appender);}
189 #define GR_SET_APPENDER(name, appender) { \
190 gr::logger_ptr logger = gr::logger_get_logger(name); \
191 gr::logger_set_appender(logger,appender);}
193 #define GR_LOG_SET_APPENDER(logger, appender) { \
194 gr::logger_set_appender(logger, appender);}
196 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) { \
197 gr::logger_ptr logger = gr::logger_get_logger(name); \
198 gr::logger_add_console_appender(logger,target,pattern);}
200 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \
201 gr::logger_add_console_appender(logger,target,pattern);}
203 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) { \
204 gr::logger_ptr logger = gr::logger_get_logger(name); \
205 gr::logger_set_console_appender(logger,target,pattern);}
207 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) { \
208 gr::logger_set_console_appender(logger,target,pattern);}
210 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) { \
211 gr::logger_ptr logger = gr::logger_get_logger(name); \
212 gr::logger_add_file_appender(logger,filename,append,pattern);}
214 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \
215 gr::logger_add_file_appender(logger,filename,append,pattern);}
217 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) { \
218 gr::logger_ptr logger = gr::logger_get_logger(name); \
219 gr::logger_set_file_appender(logger,filename,append,pattern);}
221 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) { \
222 gr::logger_set_file_appender(logger,filename,append,pattern);}
224 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \
225 gr::logger_ptr logger = gr::logger_get_logger(name); \
226 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
228 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \
229 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
231 #define GR_GET_LOGGER_NAMES(names) { \
232 names = gr::logger_get_logger_names();}
234 #define GR_RESET_CONFIGURATION() \
235 gr::logger_config::reset_config();
238 #define GR_DEBUG(name, msg) { \
239 gr::logger_ptr logger = gr::logger_get_logger(name); \
240 *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
242 #define GR_INFO(name, msg) { \
243 gr::logger_ptr logger = gr::logger_get_logger(name); \
244 *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
246 #define GR_NOTICE(name, msg) { \
247 gr::logger_ptr logger = gr::logger_get_logger(name); \
248 *logger << log4cpp::Priority::NOTICE << msg;}
250 #define GR_WARN(name, msg) { \
251 gr::logger_ptr logger = gr::logger_get_logger(name); \
252 *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
254 #define GR_ERROR(name, msg) { \
255 gr::logger_ptr logger = gr::logger_get_logger(name); \
256 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
258 #define GR_CRIT(name, msg) { \
259 gr::logger_ptr logger = gr::logger_get_logger(name); \
260 *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
262 #define GR_ALERT(name, msg) { \
263 gr::logger_ptr logger = gr::logger_get_logger(name); \
264 *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
266 #define GR_FATAL(name, msg) { \
267 gr::logger_ptr logger = gr::logger_get_logger(name); \
268 *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
270 #define GR_EMERG(name, msg) { \
271 gr::logger_ptr logger = gr::logger_get_logger(name); \
272 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
274 #define GR_ERRORIF(name, cond, msg) { \
276 gr::logger_ptr logger = gr::logger_get_logger(name); \
277 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
280 #define GR_ASSERT(name, cond, msg) { \
282 gr::logger_ptr logger = gr::logger_get_logger(name); \
283 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \
288 #define GR_LOG_DEBUG(logger, msg) { \
289 *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
291 #define GR_LOG_INFO(logger, msg) { \
292 *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
294 #define GR_LOG_NOTICE(logger, msg) { \
295 *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
297 #define GR_LOG_WARN(logger, msg) { \
298 *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
300 #define GR_LOG_ERROR(logger, msg) { \
301 *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
303 #define GR_LOG_CRIT(logger, msg) { \
304 *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
306 #define GR_LOG_ALERT(logger, msg) { \
307 *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
309 #define GR_LOG_FATAL(logger, msg) { \
310 *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
312 #define GR_LOG_EMERG(logger, msg) { \
313 *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
315 #define GR_LOG_ERRORIF(logger,cond, msg) { \
317 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
320 #define GR_LOG_ASSERT(logger, cond, msg) { \
322 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
337 std::string filename;
339 unsigned int watch_period;
347 static void watch_file(std::string filename,
unsigned int watch_period);
349 static bool logger_configured;
379 logger_config(logger_config
const&);
380 void operator=(logger_config
const&);
382 std::string get_filename4rpc() {
385 int get_watchperiod4rpc(){
return watch_period;};
387 std::string get_config4rpc() {
391 void set_config4rpc(std::string set) {
392 printf(
"Set string was:%s\n", set.c_str());
401 static logger_config& get_instance(
void);
405 static std::string get_filename();
407 static unsigned int get_watch_period();
412 static void load_config(std::string filename,
unsigned int watch_period=0);
414 static void stop_watch();
416 static void reset_config(
void);
438 GR_RUNTIME_API bool logger_load_config(
const std::string &config_filename=
"");
468 const std::string &level);
491 log4cpp::Priority::Value level);
536 log4cpp::Priority::Value &level);
547 std::string appender);
558 std::string appender);
571 std::string pattern);
584 std::string pattern);
597 std::string filename,
598 bool append, std::string pattern);
610 std::string filename,
611 bool append, std::string pattern);
627 size_t filesize,
int bkup_index,
bool append,
628 mode_t mode,std::string pattern);
637 GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(
void);
650 #define GR_LOG_DECLARE_LOGPTR(logger)
651 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
652 #define GR_CONFIG_LOGGER(config)
653 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
654 #define GR_LOG_GETLOGGER(logger, name)
655 #define GR_SET_LEVEL(name, level)
656 #define GR_LOG_SET_LEVEL(logger, level)
657 #define GR_GET_LEVEL(name, level)
658 #define GR_LOG_GET_LEVEL(logger, level)
659 #define GR_ADD_APPENDER(name,appender)
660 #define GR_LOG_ADD_APPENDER(logger,appender)
661 #define GR_SET_APPENDER(name,appender)
662 #define GR_LOG_SET_APPENDER(logger,appender)
663 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
664 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
665 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
666 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
667 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
668 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
669 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
670 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
671 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
672 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
673 #define GR_GET_LOGGER_NAMES(names)
674 #define GR_RESET_CONFIGURATION()
675 #define GR_DEBUG(name, msg)
676 #define GR_INFO(name, msg)
677 #define GR_NOTICE(name, msg)
678 #define GR_WARN(name, msg)
679 #define GR_ERROR(name, msg)
680 #define GR_ALERT(name, msg)
681 #define GR_CRIT(name, msg)
682 #define GR_FATAL(name, msg)
683 #define GR_EMERG(name, msg)
684 #define GR_ERRORIF(name, cond, msg)
685 #define GR_ASSERT(name, cond, msg)
686 #define GR_LOG_DEBUG(logger, msg)
687 #define GR_LOG_INFO(logger, msg)
688 #define GR_LOG_NOTICE(logger, msg)
689 #define GR_LOG_WARN(logger, msg)
690 #define GR_LOG_ERROR(logger, msg)
691 #define GR_LOG_ALERT(logger, msg)
692 #define GR_LOG_CRIT(logger, msg)
693 #define GR_LOG_FATAL(logger, msg)
694 #define GR_LOG_EMERG(logger, msg)
695 #define GR_LOG_ERRORIF(logger, cond, msg)
696 #define GR_LOG_ASSERT(logger, cond, msg)
804 int bkup_index,
bool append, mode_t mode,
805 std::string pattern) {
807 bkup_index,append,mode,pattern);
822 unsigned int watch_period = 0);
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:88
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:803
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:732
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:106
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:108
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:110
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:750
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:107
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:74
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:778
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:90
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:759
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:84
#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:723
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:756
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:747
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:793
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:735
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:104
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:762
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:112
boost::thread thread
Definition: thread.h:45
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:86
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:741
void add_appender(std::string appender)
inline function, Method to add appender to logger by name (define appender in conf file) ...
Definition: logger.h:772
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:768
#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:783
~logger()
Destructor.
Definition: logger.h:728
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:738
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:753
#define GR_LOG_ALERT(logger, msg)
Definition: logger.h:109
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:82
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:765
#define GR_LOG_SET_APPENDER(logger, appender)
Definition: logger.h:80
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:798
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:115
#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:713
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:788
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:744
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:111
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:69
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:105
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:113