29 #ifndef INCLUDED_GR_LOGGER_H
30 #define INCLUDED_GR_LOGGER_H
46 typedef unsigned short mode_t;
48 #include <sys/types.h>
55 #include <boost/filesystem.hpp>
56 #include <boost/thread.hpp>
57 #include <boost/format.hpp>
70 #define GR_LOG_DECLARE_LOGPTR(logger)
71 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
72 #define GR_CONFIG_LOGGER(config)
73 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
74 #define GR_LOG_GETLOGGER(logger, name)
75 #define GR_SET_LEVEL(name, level)
76 #define GR_LOG_SET_LEVEL(logger, level)
77 #define GR_GET_LEVEL(name, level)
78 #define GR_LOG_GET_LEVEL(logger, level)
79 #define GR_ADD_APPENDER(name,appender)
80 #define GR_LOG_ADD_APPENDER(logger,appender)
81 #define GR_SET_APPENDER(name,appender)
82 #define GR_LOG_SET_APPENDER(logger,appender)
83 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
84 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
85 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
86 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
87 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
88 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
89 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
90 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
91 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
92 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
93 #define GR_GET_LOGGER_NAMES(names)
94 #define GR_RESET_CONFIGURATION()
95 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
96 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
97 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
98 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
99 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
100 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
101 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
102 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
103 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
104 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
105 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
106 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
107 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
108 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
109 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
110 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
111 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
112 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
113 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
114 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
115 #define GR_LOG_ERRORIF(logger, cond, msg) { \
116 if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
117 #define GR_LOG_ASSERT(logger, cond, msg) { \
118 if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
124 #include <log4cpp/Category.hh>
125 #include <log4cpp/PropertyConfigurator.hh>
126 #include <log4cpp/FileAppender.hh>
127 #include <log4cpp/RollingFileAppender.hh>
128 #include <log4cpp/OstreamAppender.hh>
129 #include <log4cpp/PatternLayout.hh>
155 #define GR_LOG_DECLARE_LOGPTR(logger) \
156 gr::logger_ptr logger;
158 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \
159 logger = gr::logger_get_logger(name);
161 #define GR_CONFIG_LOGGER(config) \
162 gr::logger_config::load_config(config)
164 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
165 gr::logger_config::load_config(config,period)
167 #define GR_LOG_GETLOGGER(logger, name) \
168 gr::logger_ptr logger = gr::logger_get_logger(name);
170 #define GR_SET_LEVEL(name, level) { \
171 gr::logger_ptr logger = gr::logger_get_logger(name); \
172 gr::logger_set_level(logger,level);}
174 #define GR_LOG_SET_LEVEL(logger, level) \
175 gr::logger_set_level(logger, level);
177 #define GR_GET_LEVEL(name, level) { \
178 gr::logger_ptr logger = gr::logger_get_logger(name); \
179 gr::logger_get_level(logger,level);}
181 #define GR_LOG_GET_LEVEL(logger, level) \
182 gr::logger_get_level(logger,level);
184 #define GR_ADD_APPENDER(name, appender) { \
185 gr::logger_ptr logger = gr::logger_get_logger(name); \
186 gr::logger_add_appender(logger,appender);}
188 #define GR_LOG_ADD_APPENDER(logger, appender) { \
189 gr::logger_add_appender(logger, appender);}
191 #define GR_SET_APPENDER(name, appender) { \
192 gr::logger_ptr logger = gr::logger_get_logger(name); \
193 gr::logger_set_appender(logger,appender);}
195 #define GR_LOG_SET_APPENDER(logger, appender) { \
196 gr::logger_set_appender(logger, appender);}
198 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) { \
199 gr::logger_ptr logger = gr::logger_get_logger(name); \
200 gr::logger_add_console_appender(logger,target,pattern);}
202 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \
203 gr::logger_add_console_appender(logger,target,pattern);}
205 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) { \
206 gr::logger_ptr logger = gr::logger_get_logger(name); \
207 gr::logger_set_console_appender(logger,target,pattern);}
209 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) { \
210 gr::logger_set_console_appender(logger,target,pattern);}
212 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) { \
213 gr::logger_ptr logger = gr::logger_get_logger(name); \
214 gr::logger_add_file_appender(logger,filename,append,pattern);}
216 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \
217 gr::logger_add_file_appender(logger,filename,append,pattern);}
219 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) { \
220 gr::logger_ptr logger = gr::logger_get_logger(name); \
221 gr::logger_set_file_appender(logger,filename,append,pattern);}
223 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) { \
224 gr::logger_set_file_appender(logger,filename,append,pattern);}
226 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \
227 gr::logger_ptr logger = gr::logger_get_logger(name); \
228 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
230 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \
231 gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
233 #define GR_GET_LOGGER_NAMES(names) { \
234 names = gr::logger_get_logger_names();}
236 #define GR_RESET_CONFIGURATION() \
237 gr::logger_config::reset_config();
240 #define GR_DEBUG(name, msg) { \
241 gr::logger_ptr logger = gr::logger_get_logger(name); \
242 *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
244 #define GR_INFO(name, msg) { \
245 gr::logger_ptr logger = gr::logger_get_logger(name); \
246 *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
248 #define GR_NOTICE(name, msg) { \
249 gr::logger_ptr logger = gr::logger_get_logger(name); \
250 *logger << log4cpp::Priority::NOTICE << msg;}
252 #define GR_WARN(name, msg) { \
253 gr::logger_ptr logger = gr::logger_get_logger(name); \
254 *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
256 #define GR_ERROR(name, msg) { \
257 gr::logger_ptr logger = gr::logger_get_logger(name); \
258 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
260 #define GR_CRIT(name, msg) { \
261 gr::logger_ptr logger = gr::logger_get_logger(name); \
262 *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
264 #define GR_ALERT(name, msg) { \
265 gr::logger_ptr logger = gr::logger_get_logger(name); \
266 *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
268 #define GR_FATAL(name, msg) { \
269 gr::logger_ptr logger = gr::logger_get_logger(name); \
270 *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
272 #define GR_EMERG(name, msg) { \
273 gr::logger_ptr logger = gr::logger_get_logger(name); \
274 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
276 #define GR_ERRORIF(name, cond, msg) { \
278 gr::logger_ptr logger = gr::logger_get_logger(name); \
279 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
282 #define GR_ASSERT(name, cond, msg) { \
284 gr::logger_ptr logger = gr::logger_get_logger(name); \
285 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \
290 #define GR_LOG_DEBUG(logger, msg) { \
291 *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
293 #define GR_LOG_INFO(logger, msg) { \
294 *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
296 #define GR_LOG_NOTICE(logger, msg) { \
297 *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
299 #define GR_LOG_WARN(logger, msg) { \
300 *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
302 #define GR_LOG_ERROR(logger, msg) { \
303 *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
305 #define GR_LOG_CRIT(logger, msg) { \
306 *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
308 #define GR_LOG_ALERT(logger, msg) { \
309 *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
311 #define GR_LOG_FATAL(logger, msg) { \
312 *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
314 #define GR_LOG_EMERG(logger, msg) { \
315 *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
317 #define GR_LOG_ERRORIF(logger,cond, msg) { \
319 *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
322 #define GR_LOG_ASSERT(logger, cond, msg) { \
324 *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
339 std::string filename;
341 unsigned int watch_period;
349 static void watch_file(std::string filename,
unsigned int watch_period);
351 static bool logger_configured;
384 std::string get_filename4rpc() {
387 int get_watchperiod4rpc(){
return watch_period;};
389 std::string get_config4rpc() {
393 void set_config4rpc(std::string set) {
394 printf(
"Set string was:%s\n", set.c_str());
407 static std::string get_filename();
409 static unsigned int get_watch_period();
414 static void load_config(std::string filename,
unsigned int watch_period=0);
416 static void stop_watch();
418 static void reset_config(
void);
470 const std::string &level);
493 log4cpp::Priority::Value level);
538 log4cpp::Priority::Value &level);
549 std::string appender);
560 std::string appender);
573 std::string pattern);
586 std::string pattern);
599 std::string filename,
600 bool append, std::string pattern);
612 std::string filename,
613 bool append, std::string pattern);
629 size_t filesize,
int bkup_index,
bool append,
630 mode_t mode,std::string pattern);
652 #define GR_LOG_DECLARE_LOGPTR(logger)
653 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
654 #define GR_CONFIG_LOGGER(config)
655 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
656 #define GR_LOG_GETLOGGER(logger, name)
657 #define GR_SET_LEVEL(name, level)
658 #define GR_LOG_SET_LEVEL(logger, level)
659 #define GR_GET_LEVEL(name, level)
660 #define GR_LOG_GET_LEVEL(logger, level)
661 #define GR_ADD_APPENDER(name,appender)
662 #define GR_LOG_ADD_APPENDER(logger,appender)
663 #define GR_SET_APPENDER(name,appender)
664 #define GR_LOG_SET_APPENDER(logger,appender)
665 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
666 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
667 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
668 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
669 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
670 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
671 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
672 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
673 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
674 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
675 #define GR_GET_LOGGER_NAMES(names)
676 #define GR_RESET_CONFIGURATION()
677 #define GR_DEBUG(name, msg)
678 #define GR_INFO(name, msg)
679 #define GR_NOTICE(name, msg)
680 #define GR_WARN(name, msg)
681 #define GR_ERROR(name, msg)
682 #define GR_ALERT(name, msg)
683 #define GR_CRIT(name, msg)
684 #define GR_FATAL(name, msg)
685 #define GR_EMERG(name, msg)
686 #define GR_ERRORIF(name, cond, msg)
687 #define GR_ASSERT(name, cond, msg)
688 #define GR_LOG_DEBUG(logger, msg)
689 #define GR_LOG_INFO(logger, msg)
690 #define GR_LOG_NOTICE(logger, msg)
691 #define GR_LOG_WARN(logger, msg)
692 #define GR_LOG_ERROR(logger, msg)
693 #define GR_LOG_ALERT(logger, msg)
694 #define GR_LOG_CRIT(logger, msg)
695 #define GR_LOG_FATAL(logger, msg)
696 #define GR_LOG_EMERG(logger, msg)
697 #define GR_LOG_ERRORIF(logger, cond, msg)
698 #define GR_LOG_ASSERT(logger, cond, msg)
806 int bkup_index,
bool append, mode_t mode,
807 std::string pattern) {
809 bkup_index,append,mode,pattern);
824 unsigned int watch_period = 0);
850 const std::string name);
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:223
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:805
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:734
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:296
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:302
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:305
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:752
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:299
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:174
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 set_appender(std::string appender)
inline function, Method to set an appender to logger by name (define appender in conf file) ...
Definition: logger.h:780
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:230
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:761
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:209
#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:725
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:758
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:749
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:795
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:737
GR_RUNTIME_API void logger_reset_config(void)
Reset logger's configuration file.
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:290
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:764
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:314
boost::thread thread
Definition: thread.h:45
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:216
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:743
Include this header to use the message passing features.
Definition: logger.h:131
void add_appender(std::string appender)
inline function, Method to add appender to logger by name (define appender in conf file) ...
Definition: logger.h:774
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:770
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:181
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:785
~logger()
Destructor.
Definition: logger.h:730
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:740
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:755
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:308
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:202
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:767
#define GR_LOG_SET_APPENDER(logger, appender)
Definition: logger.h:195
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 cna launch a thread to wathc a con...
Definition: logger.h:335
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:800
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:149
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:322
#define GR_LOG_ADD_APPENDER(logger, appender)
Definition: logger.h:188
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:715
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:790
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:746
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:311
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:158
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:293
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:317
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...