GNU Radio 3.7.3 C++ API
logger.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012-2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 /*******************************************************************************
24 * Author: Mark Plett
25 * Description:
26 * The gr::logger module wraps the log4cpp library for logging in gnuradio
27 *******************************************************************************/
28 
29 #ifndef INCLUDED_GR_LOGGER_H
30 #define INCLUDED_GR_LOGGER_H
31 
32 /*!
33 * \ingroup logging
34 * \brief GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
35 *
36 */
37 
38 #ifndef ENABLE_GR_LOG
39 #define ENABLE_GR_LOG
40 #endif
41 #ifndef HAVE_LOG4CPP
42 /* #undef HAVE_LOG4CPP */
43 #endif
44 
45 #ifdef _MSC_VER
46 typedef unsigned short mode_t;
47 #endif
48 
49 #include <gnuradio/api.h>
50 #include <assert.h>
51 #include <iostream>
52 #include <time.h>
53 #include <boost/filesystem.hpp>
54 #include <boost/thread.hpp>
55 #include <boost/format.hpp>
56 #include <pmt/pmt.h>
57 
58 #ifdef ENABLE_GR_LOG
59 
60 // We have three configurations... first logging to stdout/stderr
61 #ifndef HAVE_LOG4CPP
62 
63 namespace gr {
64  //#warning GR logging Enabled and using std::cout
65  typedef std::string logger_ptr;
66 } /* namespace gr */
67 
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);};}
111 
112 
113 #else /* HAVE_LOG4CPP */
114 
115 // Second configuration...logging to log4cpp
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>
122 
123 namespace gr {
124 
125  /*!
126  * \brief GR_LOG macros
127  * \ingroup logging
128  *
129  * These macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros
130  * are:
131  * LOG_DEBUG
132  * LOG_INFO
133  * LOG_WARN
134  * LOG_TRACE
135  * LOG_ERROR
136  * LOG_ALERT
137  * LOG_CRIT
138  * LOG_FATAL
139  * LOG_EMERG
140  */
141  typedef log4cpp::Category* logger_ptr;
142 
143 } /* namespace gr */
144 
145 
146  /* Macros for Programmatic Configuration */
147 #define GR_LOG_DECLARE_LOGPTR(logger) \
148  gr::logger_ptr logger;
149 
150 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \
151  logger = gr::logger_get_logger(name);
152 
153 #define GR_CONFIG_LOGGER(config) \
154  gr::logger_config::load_config(config)
155 
156 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
157  gr::logger_config::load_config(config,period)
158 
159 #define GR_LOG_GETLOGGER(logger, name) \
160  gr::logger_ptr logger = gr::logger_get_logger(name);
161 
162 #define GR_SET_LEVEL(name, level) { \
163  gr::logger_ptr logger = gr::logger_get_logger(name); \
164  gr::logger_set_level(logger,level);}
165 
166 #define GR_LOG_SET_LEVEL(logger, level) \
167  gr::logger_set_level(logger, level);
168 
169 #define GR_GET_LEVEL(name, level) { \
170  gr::logger_ptr logger = gr::logger_get_logger(name); \
171  gr::logger_get_level(logger,level);}
172 
173 #define GR_LOG_GET_LEVEL(logger, level) \
174  gr::logger_get_level(logger,level);
175 
176 #define GR_ADD_APPENDER(name, appender) { \
177  gr::logger_ptr logger = gr::logger_get_logger(name); \
178  gr::logger_add_appender(logger,appender);}
179 
180 #define GR_LOG_ADD_APPENDER(logger, appender) { \
181  gr::logger_add_appender(logger, appender);}
182 
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);}
186 
187 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \
188  gr::logger_add_console_appender(logger,target,pattern);}
189 
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);}
193 
194 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \
195  gr::logger_add_file_appender(logger,filename,append,pattern);}
196 
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);}
200 
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);}
203 
204 #define GR_GET_LOGGER_NAMES(names) { \
205  names = gr::logger_get_logger_names();}
206 
207 #define GR_RESET_CONFIGURATION() \
208  gr::logger_config::reset_config();
209 
210  /* Logger name referenced macros */
211 #define GR_DEBUG(name, msg) { \
212  gr::logger_ptr logger = gr::logger_get_logger(name); \
213  *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
214 
215 #define GR_INFO(name, msg) { \
216  gr::logger_ptr logger = gr::logger_get_logger(name); \
217  *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
218 
219 #define GR_NOTICE(name, msg) { \
220  gr::logger_ptr logger = gr::logger_get_logger(name); \
221  *logger << log4cpp::Priority::NOTICE << msg;}
222 
223 #define GR_WARN(name, msg) { \
224  gr::logger_ptr logger = gr::logger_get_logger(name); \
225  *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
226 
227 #define GR_ERROR(name, msg) { \
228  gr::logger_ptr logger = gr::logger_get_logger(name); \
229  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
230 
231 #define GR_CRIT(name, msg) { \
232  gr::logger_ptr logger = gr::logger_get_logger(name); \
233  *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
234 
235 #define GR_ALERT(name, msg) { \
236  gr::logger_ptr logger = gr::logger_get_logger(name); \
237  *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
238 
239 #define GR_FATAL(name, msg) { \
240  gr::logger_ptr logger = gr::logger_get_logger(name); \
241  *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
242 
243 #define GR_EMERG(name, msg) { \
244  gr::logger_ptr logger = gr::logger_get_logger(name); \
245  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
246 
247 #define GR_ERRORIF(name, cond, msg) { \
248  if((cond)) { \
249  gr::logger_ptr logger = gr::logger_get_logger(name); \
250  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
251  }
252 
253 #define GR_ASSERT(name, cond, msg) { \
254  if(!(cond)) { \
255  gr::logger_ptr logger = gr::logger_get_logger(name); \
256  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \
257  assert(0); \
258  }
259 
260  /* LoggerPtr Referenced Macros */
261 #define GR_LOG_DEBUG(logger, msg) { \
262  *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
263 
264 #define GR_LOG_INFO(logger, msg) { \
265  *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
266 
267 #define GR_LOG_NOTICE(logger, msg) { \
268  *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
269 
270 #define GR_LOG_WARN(logger, msg) { \
271  *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
272 
273 #define GR_LOG_ERROR(logger, msg) { \
274  *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
275 
276 #define GR_LOG_CRIT(logger, msg) { \
277  *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
278 
279 #define GR_LOG_ALERT(logger, msg) { \
280  *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
281 
282 #define GR_LOG_FATAL(logger, msg) { \
283  *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
284 
285 #define GR_LOG_EMERG(logger, msg) { \
286  *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
287 
288 #define GR_LOG_ERRORIF(logger,cond, msg) { \
289  if((cond)) { \
290  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
291  }
292 
293 #define GR_LOG_ASSERT(logger, cond, msg) { \
294  if(!(cond)) { \
295  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
296  assert(0);} \
297  }
298 
299 namespace gr {
300 
301  /*!
302  * \brief Class to control configuration of logger.
303  * This is a singleton that cna launch a thread to wathc a config file for changes
304  * \ingroup logging
305  */
306  class logger_config
307  {
308  private:
309  /*! \brief filename of logger config file */
310  std::string filename;
311  /*! \brief Period (seconds) over which watcher thread checks config file for changes */
312  unsigned int watch_period;
313  /*! \brief Pointer to watch thread for config file changes */
314  boost::thread *watch_thread;
315 
316  /*! \brief Watcher thread method
317  * /param filename Name of configuration file
318  * /param watch_period Seconds between checks for changes in config file
319  */
320  static void watch_file(std::string filename,unsigned int watch_period);
321 
322  static bool logger_configured;
323 
324  logger_config()/*:
325  rpc_get_filename("logger_config", "filename", &logger_config::get_filename4rpc,
326  pmt::mp(""), pmt::mp(""), pmt::mp(""),
327  "", "filename", RPC_PRIVLVL_MIN,
328  DISPTIME | DISPOPTSTRIP),
329  rpc_get_watchperiod("logger_config", "watch_period", &logger_config::get_watchperiod4rpc,
330  pmt::mp(0), pmt::mp(32768), pmt::mp(0),
331  "", "watch_period", RPC_PRIVLVL_MIN,
332  DISPTIME | DISPOPTSTRIP),
333  rpc_get_config("logger_config", "config", &logger_config::get_config4rpc,
334  pmt::mp(""), pmt::mp(""), pmt::mp(""),
335  "", "filename", RPC_PRIVLVL_MIN,
336  DISPTIME | DISPOPTSTRIP),
337  rpc_set_config("logger_config","config", &logger_config::set_config4rpc,
338  pmt::mp(""), pmt::mp(""), pmt::mp(""),
339  "", "filename", RPC_PRIVLVL_MIN,
340  DISPTIME | DISPOPTSTRIP)
341  */
342  {
343  } //!< Constructor
344 
345  /*
346  rpcbasic_register_get<logger_config,std::string> rpc_get_filename;
347  rpcbasic_register_get<logger_config,int> rpc_get_watchperiod;
348  rpcbasic_register_get<logger_config,std::string> rpc_get_config;
349  rpcbasic_register_set<logger_config,std::string> rpc_set_config;
350  */
351 
352  logger_config(logger_config const&); //!<Copy constructor
353  void operator=(logger_config const&); //!<Assignment Operator
354 
355  std::string get_filename4rpc() {
356  return filename;
357  }
358  int get_watchperiod4rpc(){return watch_period;};
359 
360  std::string get_config4rpc() {
361  return filename;
362  }
363 
364  void set_config4rpc(std::string set) {
365  printf("Set string was:%s\n", set.c_str());
366  }
367 
368  /*! \brief destrcutor stops watch thread before exits */
369  ~logger_config() {
370  stop_watch();
371  }
372 
373  /*! \brief Instance getter for singleton. Only used by class. */
374  static logger_config& get_instance(void);
375 
376  public:
377  /*! \brief Getter for config filename */
378  static std::string get_filename();
379  /*! \brief Getter for watch period */
380  static unsigned int get_watch_period();
381  /*! \brief Method to load configuration
382  * /param filename Name of configuration file
383  * /param watch_period Seconds between checks for changes in config file
384  */
385  static void load_config(std::string filename,unsigned int watch_period=0);
386  /*! \brief Method to stop watcher thread */
387  static void stop_watch();
388  /*! \brief method to reset logger configuration */
389  static void reset_config(void);
390  };
391 
392  /*!
393  * \brief Retrieve a pointer to a logger by name
394  *
395  * Retrives a logger pointer
396  * \p name.
397  *
398  * \param name Name of the logger for which a pointer is requested
399  */
400  GR_RUNTIME_API logger_ptr logger_get_logger(std::string name);
401 
402  /*!
403  * \brief Load logger's configuration file.
404  *
405  * Initialize the GNU Radio logger by loading the configuration file
406  * \p config_filename.
407  *
408  * \param config_filename The configuration file. Set to "" for the
409  * basic logger that outputs to the console.
410  */
411  GR_RUNTIME_API bool logger_load_config(const std::string &config_filename="");
412 
413  /*!
414  * \brief Reset logger's configuration file.
415  *
416  * Remove all appenders from loggers
417  */
418  GR_RUNTIME_API void logger_reset_config(void);
419 
420  /*!
421  * \brief Set the logger's output level.
422  *
423  * Sets the level of the logger. This takes a string that is
424  * translated to the standard levels and can be (case insensitive):
425  *
426  * \li off , notset
427  * \li debug
428  * \li info
429  * \li notice
430  * \li warn
431  * \li error
432  * \li crit
433  * \li alert
434  * \li fatal
435  * \li emerg
436  *
437  * \param logger the logger to set the level of.
438  * \param level string to set the level to.
439  */
440  GR_RUNTIME_API void logger_set_level(logger_ptr logger,
441  const std::string &level);
442 
443  /*!
444  * \brief Set the logger's output level.
445  *
446  * Sets the level of the logger. This takes the actual Log4cpp::Priority
447  * data type, which can be:
448  *
449  * \li log4cpp::Priority::NOTSET
450  * \li log4cpp::Priority::DEBUG
451  * \li log4cpp::Priority::INFO
452  * \li log4cpp::Priority::NOTICE
453  * \li log4cpp::Priority::WARN
454  * \li log4cpp::Priority::ERROR
455  * \li log4cpp::Priority::CRIT
456  * \li log4cpp::Priority::ALERT
457  * \li log4cpp::Priority::FATAL
458  * \li log4cpp::Priority::EMERG
459  *
460  * \param logger the logger to set the level of.
461  * \param level new logger level of type Log4cpp::Priority
462  */
463  GR_RUNTIME_API void logger_set_level(logger_ptr logger,
464  log4cpp::Priority::Value level);
465 
466  /*!
467  * \brief Get the logger's output level.
468  *
469  * Gets the level of the logger. This returns a string that
470  * corresponds to the standard levels and can be (case insensitive):
471  *
472  * \li notset
473  * \li debug
474  * \li info
475  * \li notice
476  * \li warn
477  * \li error
478  * \li crit
479  * \li alert
480  * \li fatal
481  * \li emerg
482  *
483  * \param logger the logger to get the level of.
484  * \param level string to get the level into.
485  */
486  GR_RUNTIME_API void logger_get_level(logger_ptr logger, std::string &level);
487 
488  /*!
489  * \brief Get the logger's output level.
490  *
491  * Gets the level of the logger. This returns the actual Log4cpp::Level
492  * data type, which can be:
493  *
494  * \li log4cpp::Priority::NOTSET
495  * \li log4cpp::Priority::DEBUG
496  * \li log4cpp::Priority::INFO
497  * \li log4cpp::Priority::NOTICE
498  * \li log4cpp::Priority::WARN
499  * \li log4cpp::Priority::ERROR
500  * \li log4cpp::Priority::CRIT
501  * \li log4cpp::Priority::ALERT
502  * \li log4cpp::Priority::FATAL
503  * \li log4cpp::Priority::EMERG
504  *
505  * \param logger the logger to get the level of.
506  * \param level of the logger.
507  */
508  GR_RUNTIME_API void logger_get_level(logger_ptr logger,
509  log4cpp::Priority::Value &level);
510 
511  /*!
512  * \brief Add console appender to a given logger
513  *
514  * Add console appender to a given logger
515  *
516  * \param logger Logger to which appender will be added
517  * \param appender Name of appender to add to logger
518  */
519  GR_RUNTIME_API void logger_add_appender(logger_ptr logger,
520  std::string appender);
521 
522  /*!
523  * \brief Add console appender to a given logger
524  *
525  * Add console appender to a given logger
526  *
527  * \param logger Logger to which appender will be added
528  * \param target Std target to write 'cout' or 'cerr' (default is cout)
529  * \param pattern Formating pattern for log messages
530  */
531  GR_RUNTIME_API void logger_add_console_appender(logger_ptr logger,
532  std::string target,
533  std::string pattern);
534 
535  /*!
536  * \brief Add file appender to a given logger
537  *
538  * Add file appender to a given logger
539  *
540  * \param logger Logger to which appender will be added
541  * \param filename File to which log will be written
542  * \param append Overwrite or append to log file
543  * \param pattern Formating pattern for log messages
544  */
545  GR_RUNTIME_API void logger_add_file_appender(logger_ptr logger,
546  std::string filename,
547  bool append, std::string pattern);
548 
549  /*!
550  * \brief Add rolling file appender to a given logger
551  *
552  * Add rolling file appender to a given logger
553  *
554  * \param logger Logger to which appender will be added
555  * \param filename File to which log will be written
556  * \param filesize Sizez of files to write
557  * \param bkup_index Number of files to write
558  * \param append Overwrite or append to log file
559  * \param mode Permissions to set on log file
560  * \param pattern Formating pattern for log messages
561  */
562  GR_RUNTIME_API void logger_add_rollingfile_appender(logger_ptr logger, std::string filename,
563  size_t filesize, int bkup_index, bool append,
564  mode_t mode,std::string pattern);
565 
566  /*!
567  * \brief Add rolling file appender to a given logger
568  *
569  * Add rolling file appender to a given logger
570  *
571  * \return vector of string names of loggers
572  */
573  GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(void);
574 
575 } /* namespace gr */
576 
577 #endif /* HAVE_LOG4CPP */
578 
579  // If Logger disable do nothing
580 #else /* ENABLE_GR_LOG */
581 
582 namespace gr {
583  typedef void* logger_ptr;
584 } /* namespace gr */
585 
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)
627 
628 #endif /* ENABLE_GR_LOG */
629 
630 namespace gr {
631 
632  // Even if logger is disabled we'll need for methods below to exist in python.
633  // The macros these call will be disabled if ENABLE_GR_LOG is undefined
634 
635  /********************* Start Classes and Methods for Python ******************/
636  /*!
637  * \brief Logger class for referencing loggers in python. Not
638  * needed in C++ (use macros) Wraps and manipulates loggers for
639  * python as python has no macros
640  * \ingroup logging
641  *
642  */
643  class logger
644  {
645  private:
646  /*! \brief logger pointer to logger associated wiith this wrapper class */
647  logger_ptr d_logger;
648  public:
649  /*!
650  * \brief contructor Provide name of logger to associate with this class
651  * \param logger_name Name of logger associated with class
652  */
653  logger(std::string logger_name) {
654  GR_LOG_ASSIGN_LOGPTR(d_logger,logger_name);
655  };
656 
657  /*! \brief Destructor */
658  ~logger(){;}
659 
660  // Wrappers for logging macros
661  /*! \brief inline function, wrapper to set the logger level */
662  void set_level(std::string level){GR_LOG_SET_LEVEL(d_logger,level);}
663 
664  /*! \brief inline function, wrapper to get the logger level */
665  void get_level(std::string &level){GR_LOG_GET_LEVEL(d_logger,level);}
666 
667  /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
668  void debug(std::string msg){GR_LOG_DEBUG(d_logger,msg);};
669 
670  /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
671  void info(std::string msg){GR_LOG_INFO(d_logger,msg);}
672 
673  /*! \brief inline function, wrapper for NOTICE message */
674  void notice(std::string msg){GR_LOG_NOTICE(d_logger,msg);}
675 
676  /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
677  void warn(std::string msg){GR_LOG_WARN(d_logger,msg);}
678 
679  /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
680  void error(std::string msg){GR_LOG_ERROR(d_logger,msg);}
681 
682  /*! \brief inline function, wrapper for NOTICE message */
683  void crit(std::string msg){GR_LOG_CRIT(d_logger,msg);}
684 
685  /*! \brief inline function, wrapper for ALERT message */
686  void alert(std::string msg){GR_LOG_ALERT(d_logger,msg);}
687 
688  /*! \brief inline function, wrapper for FATAL message */
689  void fatal(std::string msg){GR_LOG_FATAL(d_logger,msg);}
690 
691  /*! \brief inline function, wrapper for EMERG message */
692  void emerg(std::string msg){GR_LOG_EMERG(d_logger,msg);}
693 
694  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
695  void errorIF(bool cond,std::string msg){GR_LOG_ERRORIF(d_logger,cond,msg);}
696 
697  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
698  void log_assert(bool cond,std::string msg){GR_LOG_ASSERT(d_logger,cond,msg);}
699 
700  /*! \brief inline function, Method to add appender to logger by
701  name (define appender in conf file) */
702  void add_appender(std::string appender) {
703  GR_LOG_ADD_APPENDER(d_logger, appender);
704  }
705 
706  /*! \brief inline function, Method to add console appender to logger */
707  void add_console_appender(std::string target,std::string pattern) {
708  GR_LOG_ADD_CONSOLE_APPENDER(d_logger, target, pattern);
709  }
710 
711  /*! \brief inline function, Method to add file appender to logger */
712  void add_file_appender(std::string filename, bool append, std::string pattern) {
713  GR_LOG_ADD_FILE_APPENDER(d_logger, filename, append, pattern);
714  }
715 
716  /*! \brief inline function, Method to add rolling file appender to logger */
717  void add_rollingfile_appender(std::string filename, size_t filesize,
718  int bkup_index, bool append, mode_t mode,
719  std::string pattern) {
720  GR_LOG_ADD_ROLLINGFILE_APPENDER(d_logger,filename,filesize,
721  bkup_index,append,mode,pattern);
722  }
723  };
724 
725 } /* namespace gr */
726 
727 /**************** Start Configuration Class and Methods for Python ************/
728 /*!
729  * \brief Function to call configuration macro from python.
730  * Note: Configuration is only updated if filename or watch_period has changed.
731  * \param config_filename Name of configuration file
732  * \param watch_period Seconds to wait between checking for changes in conf file.
733  * Watch_period defaults to 0 in which case the file is not watched for changes
734  */
735 GR_RUNTIME_API void gr_logger_config(const std::string config_filename,
736  unsigned int watch_period = 0);
737 
738 /*!
739  * \brief Function to return logger names to python
740  * \return Vector of name strings
741  *
742  */
743 GR_RUNTIME_API std::vector<std::string> gr_logger_get_logger_names(void);
744 
745 /*!
746  * \brief Function to reset logger configuration from python
747  *
748  */
750 
751 #endif /* INCLUDED_GR_LOGGER_H */
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