GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
The Free & Open Software Radio Ecosystem
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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_LOGGER_H
12 #define INCLUDED_GR_LOGGER_H
13 
14 /*!
15  * \ingroup logging
16  * \brief GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
17  *
18  */
19 
20 #ifdef _MSC_VER
21 typedef int mode_t;
22 #else
23 #include <sys/types.h>
24 #endif
25 
26 #include <gnuradio/api.h>
27 #include <log4cpp/Category.hh>
28 #include <log4cpp/FileAppender.hh>
29 #include <log4cpp/OstreamAppender.hh>
30 #include <log4cpp/PatternLayout.hh>
31 #include <log4cpp/PropertyConfigurator.hh>
32 #include <log4cpp/RollingFileAppender.hh>
33 #include <pmt/pmt.h>
34 #include <boost/filesystem.hpp>
35 #include <boost/format.hpp>
36 #include <boost/thread.hpp>
37 #include <cassert>
38 #include <ctime>
39 #include <iostream>
40 #include <memory>
41 
42 namespace gr {
43 
44 /*!
45  * \brief GR_LOG macros
46  * \ingroup logging
47  *
48  * These macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros
49  * are:
50  * LOG_DEBUG
51  * LOG_INFO
52  * LOG_WARN
53  * LOG_TRACE
54  * LOG_ERROR
55  * LOG_ALERT
56  * LOG_CRIT
57  * LOG_FATAL
58  * LOG_EMERG
59  */
60 typedef log4cpp::Category* logger_ptr;
61 
62 } /* namespace gr */
63 
64 /* Macros for Programmatic Configuration */
65 #define GR_LOG_DECLARE_LOGPTR(logger) gr::logger_ptr logger
66 
67 #define GR_LOG_ASSIGN_LOGPTR(logger, name) logger = gr::logger_get_logger(name)
68 
69 #define GR_CONFIG_LOGGER(config) gr::logger_config::load_config(config)
70 
71 #define GR_CONFIG_AND_WATCH_LOGGER(config, period) \
72  gr::logger_config::load_config(config, period)
73 
74 #define GR_LOG_GETLOGGER(logger, name) gr::logger_ptr logger = gr::logger_get_logger(name)
75 
76 #define GR_SET_LEVEL(name, level) \
77  { \
78  gr::logger_ptr logger = gr::logger_get_logger(name); \
79  gr::logger_set_level(logger, level); \
80  }
81 
82 #define GR_LOG_SET_LEVEL(logger, level) gr::logger_set_level(logger, level)
83 
84 #define GR_GET_LEVEL(name, level) \
85  { \
86  gr::logger_ptr logger = gr::logger_get_logger(name); \
87  gr::logger_get_level(logger, level); \
88  }
89 
90 #define GR_LOG_GET_LEVEL(logger, level) gr::logger_get_level(logger, level)
91 
92 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) \
93  { \
94  gr::logger_ptr logger = gr::logger_get_logger(name); \
95  gr::logger_add_console_appender(logger, target, pattern); \
96  }
97 
98 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) \
99  { \
100  gr::logger_add_console_appender(logger, target, pattern); \
101  }
102 
103 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) \
104  { \
105  gr::logger_ptr logger = gr::logger_get_logger(name); \
106  gr::logger_set_console_appender(logger, target, pattern); \
107  }
108 
109 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) \
110  { \
111  gr::logger_set_console_appender(logger, target, pattern); \
112  }
113 
114 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) \
115  { \
116  gr::logger_ptr logger = gr::logger_get_logger(name); \
117  gr::logger_add_file_appender(logger, filename, append, pattern); \
118  }
119 
120 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) \
121  { \
122  gr::logger_add_file_appender(logger, filename, append, pattern); \
123  }
124 
125 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) \
126  { \
127  gr::logger_ptr logger = gr::logger_get_logger(name); \
128  gr::logger_set_file_appender(logger, filename, append, pattern); \
129  }
130 
131 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) \
132  { \
133  gr::logger_set_file_appender(logger, filename, append, pattern); \
134  }
135 
136 #define GR_ADD_ROLLINGFILE_APPENDER( \
137  name, filename, filesize, bkup_index, append, mode, pattern) \
138  { \
139  gr::logger_ptr logger = gr::logger_get_logger(name); \
140  gr::logger_add_rollingfile_appender( \
141  logger, filename, filesize, bkup_index, append, mode, pattern); \
142  }
143 
144 #define GR_LOG_ADD_ROLLINGFILE_APPENDER( \
145  logger, filename, filesize, bkup_index, append, mode, pattern) \
146  { \
147  gr::logger_add_rollingfile_appender( \
148  logger, filename, filesize, bkup_index, append, mode, pattern); \
149  }
150 
151 #define GR_GET_LOGGER_NAMES(names) \
152  { \
153  names = gr::logger_get_logger_names(); \
154  }
155 
156 #define GR_RESET_CONFIGURATION() gr::logger_config::reset_config();
157 
158 /* Logger name referenced macros */
159 #define GR_DEBUG(name, msg) \
160  { \
161  gr::logger_ptr logger = gr::logger_get_logger(name); \
162  *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \
163  }
164 
165 #define GR_INFO(name, msg) \
166  { \
167  gr::logger_ptr logger = gr::logger_get_logger(name); \
168  *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \
169  }
170 
171 #define GR_NOTICE(name, msg) \
172  { \
173  gr::logger_ptr logger = gr::logger_get_logger(name); \
174  *logger << log4cpp::Priority::NOTICE << (msg); \
175  }
176 
177 #define GR_WARN(name, msg) \
178  { \
179  gr::logger_ptr logger = gr::logger_get_logger(name); \
180  *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \
181  }
182 
183 #define GR_ERROR(name, msg) \
184  { \
185  gr::logger_ptr logger = gr::logger_get_logger(name); \
186  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
187  }
188 
189 #define GR_CRIT(name, msg) \
190  { \
191  gr::logger_ptr logger = gr::logger_get_logger(name); \
192  *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \
193  }
194 
195 #define GR_ALERT(name, msg) \
196  { \
197  gr::logger_ptr logger = gr::logger_get_logger(name); \
198  *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \
199  }
200 
201 #define GR_FATAL(name, msg) \
202  { \
203  gr::logger_ptr logger = gr::logger_get_logger(name); \
204  *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \
205  }
206 
207 #define GR_EMERG(name, msg) \
208  { \
209  gr::logger_ptr logger = gr::logger_get_logger(name); \
210  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
211  }
212 
213 #define GR_ERRORIF(name, cond, msg) \
214  { \
215  if ((cond)) { \
216  gr::logger_ptr logger = gr::logger_get_logger(name); \
217  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
218  } \
219  }
220 
221 #define GR_ASSERT(name, cond, msg) \
222  { \
223  if (!(cond)) { \
224  gr::logger_ptr logger = gr::logger_get_logger(name); \
225  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
226  } \
227  assert(0); \
228  }
229 
230 /* LoggerPtr Referenced Macros */
231 #define GR_LOG_DEBUG(logger, msg) \
232  { \
233  *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \
234  }
235 
236 #define GR_LOG_INFO(logger, msg) \
237  { \
238  *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \
239  }
240 
241 #define GR_LOG_NOTICE(logger, msg) \
242  { \
243  *logger << log4cpp::Priority::NOTICE << (msg) << log4cpp::eol; \
244  }
245 
246 #define GR_LOG_WARN(logger, msg) \
247  { \
248  *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \
249  }
250 
251 #define GR_LOG_ERROR(logger, msg) \
252  { \
253  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
254  }
255 
256 #define GR_LOG_CRIT(logger, msg) \
257  { \
258  *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \
259  }
260 
261 #define GR_LOG_ALERT(logger, msg) \
262  { \
263  *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \
264  }
265 
266 #define GR_LOG_FATAL(logger, msg) \
267  { \
268  *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \
269  }
270 
271 #define GR_LOG_EMERG(logger, msg) \
272  { \
273  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
274  }
275 
276 #define GR_LOG_ERRORIF(logger, cond, msg) \
277  { \
278  if ((cond)) { \
279  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
280  } \
281  }
282 
283 #define GR_LOG_ASSERT(logger, cond, msg) \
284  { \
285  if (!(cond)) { \
286  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
287  assert(0); \
288  } \
289  }
290 
291 namespace gr {
292 
293 /*!
294  * \brief Class to control configuration of logger.
295  * This is a singleton that can launch a thread to watch a config file for changes
296  * \ingroup logging
297  */
299 {
300 private:
301  /*! \brief filename of logger config file */
302  std::string filename;
303  /*! \brief Period (seconds) over which watcher thread checks config file for changes
304  */
305  unsigned int watch_period;
306  /*! \brief watch thread for config file changes */
307  std::unique_ptr<boost::thread> watch_thread;
308 
309  /*! \brief Watcher thread method
310  * /param filename Name of configuration file
311  * /param watch_period Seconds between checks for changes in config file
312  */
313  static void watch_file(std::string filename, unsigned int watch_period);
314 
315  static bool logger_configured;
316 
317  logger_config() /*:
318  rpc_get_filename("logger_config", "filename", &logger_config::get_filename4rpc,
319  pmt::mp(""), pmt::mp(""), pmt::mp(""),
320  "", "filename", RPC_PRIVLVL_MIN,
321  DISPTIME | DISPOPTSTRIP),
322  rpc_get_watchperiod("logger_config", "watch_period",
323  &logger_config::get_watchperiod4rpc, pmt::mp(0), pmt::mp(32768), pmt::mp(0),
324  "", "watch_period", RPC_PRIVLVL_MIN,
325  DISPTIME | DISPOPTSTRIP),
326  rpc_get_config("logger_config", "config", &logger_config::get_config4rpc,
327  pmt::mp(""), pmt::mp(""), pmt::mp(""),
328  "", "filename", RPC_PRIVLVL_MIN,
329  DISPTIME | DISPOPTSTRIP),
330  rpc_set_config("logger_config","config", &logger_config::set_config4rpc,
331  pmt::mp(""), pmt::mp(""), pmt::mp(""),
332  "", "filename", RPC_PRIVLVL_MIN,
333  DISPTIME | DISPOPTSTRIP)
334  */
335  {
336  } //!< Constructor
337 
338  /*
339  rpcbasic_register_get<logger_config,std::string> rpc_get_filename;
340  rpcbasic_register_get<logger_config,int> rpc_get_watchperiod;
341  rpcbasic_register_get<logger_config,std::string> rpc_get_config;
342  rpcbasic_register_set<logger_config,std::string> rpc_set_config;
343  */
344 
345  logger_config(logger_config const&); //!< Copy constructor
346  void operator=(logger_config const&); //!< Assignment Operator
347 
348  std::string get_filename4rpc() { return filename; }
349  int get_watchperiod4rpc() { return watch_period; };
350 
351  std::string get_config4rpc() { return filename; }
352 
353  void set_config4rpc(std::string set) { printf("Set string was:%s\n", set.c_str()); }
354 
355  /*! \brief Instance getter for singleton. Only used by class. */
356  static logger_config& get_instance(void);
357 
358 public:
359  /*! \brief destructor stops watch thread before exits */
360  ~logger_config() { stop_watch(); }
361  /*! \brief Getter for config filename */
362  static std::string get_filename();
363  /*! \brief Getter for watch period */
364  static unsigned int get_watch_period();
365  /*! \brief Method to load configuration
366  * /param filename Name of configuration file
367  * /param watch_period Seconds between checks for changes in config file
368  */
369  static void load_config(std::string filename, unsigned int watch_period = 0);
370  /*! \brief Method to stop watcher thread */
371  static void stop_watch();
372  /*! \brief method to reset logger configuration */
373  static void reset_config(void);
374 };
375 
376 /*!
377  * \brief Retrieve a pointer to a logger by name
378  *
379  * Retrieves a logger pointer
380  * \p name.
381  *
382  * \param name Name of the logger for which a pointer is requested
383  */
385 
386 /*!
387  * \brief Load logger's configuration file.
388  *
389  * Initialize the GNU Radio logger by loading the configuration file
390  * \p config_filename.
391  *
392  * \param config_filename The configuration file. Set to "" for the
393  * basic logger that outputs to the console.
394  */
395 GR_RUNTIME_API bool logger_load_config(const std::string& config_filename = "");
396 
397 /*!
398  * \brief Reset logger's configuration file.
399  *
400  * Remove all appenders from loggers
401  */
403 
404 /*!
405  * \brief Set the logger's output level.
406  *
407  * Sets the level of the logger. This takes a string that is
408  * translated to the standard levels and can be (case insensitive):
409  *
410  * \li off , notset
411  * \li debug
412  * \li info
413  * \li notice
414  * \li warn
415  * \li error
416  * \li crit
417  * \li alert
418  * \li fatal
419  * \li emerg
420  *
421  * \param logger the logger to set the level of.
422  * \param level string to set the level to.
423  */
424 GR_RUNTIME_API void logger_set_level(logger_ptr logger, const std::string& level);
425 
426 /*!
427  * \brief Set the logger's output level.
428  *
429  * Sets the level of the logger. This takes the actual Log4cpp::Priority
430  * data type, which can be:
431  *
432  * \li log4cpp::Priority::NOTSET
433  * \li log4cpp::Priority::DEBUG
434  * \li log4cpp::Priority::INFO
435  * \li log4cpp::Priority::NOTICE
436  * \li log4cpp::Priority::WARN
437  * \li log4cpp::Priority::ERROR
438  * \li log4cpp::Priority::CRIT
439  * \li log4cpp::Priority::ALERT
440  * \li log4cpp::Priority::FATAL
441  * \li log4cpp::Priority::EMERG
442  *
443  * \param logger the logger to set the level of.
444  * \param level new logger level of type Log4cpp::Priority
445  */
446 GR_RUNTIME_API void logger_set_level(logger_ptr logger, log4cpp::Priority::Value level);
447 
448 /*!
449  * \brief Get the logger's output level.
450  *
451  * Gets the level of the logger. This returns a string that
452  * corresponds to the standard levels and can be (case insensitive):
453  *
454  * \li notset
455  * \li debug
456  * \li info
457  * \li notice
458  * \li warn
459  * \li error
460  * \li crit
461  * \li alert
462  * \li fatal
463  * \li emerg
464  *
465  * \param logger the logger to get the level of.
466  * \param level string to get the level into.
467  */
469 
470 /*!
471  * \brief Get the logger's output level.
472  *
473  * Gets the level of the logger. This returns the actual Log4cpp::Level
474  * data type, which can be:
475  *
476  * \li log4cpp::Priority::NOTSET
477  * \li log4cpp::Priority::DEBUG
478  * \li log4cpp::Priority::INFO
479  * \li log4cpp::Priority::NOTICE
480  * \li log4cpp::Priority::WARN
481  * \li log4cpp::Priority::ERROR
482  * \li log4cpp::Priority::CRIT
483  * \li log4cpp::Priority::ALERT
484  * \li log4cpp::Priority::FATAL
485  * \li log4cpp::Priority::EMERG
486  *
487  * \param logger the logger to get the level of.
488  * \param level of the logger.
489  */
490 GR_RUNTIME_API void logger_get_level(logger_ptr logger, log4cpp::Priority::Value& level);
491 
492 /*!
493  * \brief Add console appender to a given logger
494  *
495  * Add console appender to a given logger
496  *
497  * \param logger Logger to which appender will be added
498  * \param appender Name of appender to add to logger
499  */
501 
502 /*!
503  * \brief Sets a console appender to a given logger. Deletes any
504  * existing appenders and adds a new one. To add an additional
505  * appender, use logger_add_appender.
506  *
507  * \param logger Logger to which appender will be added
508  * \param appender Name of appender to add to logger
509  */
511 
512 /*!
513  * \brief Add console appender to a given logger
514  *
515  * Add console appender to a given logger
516  *
517  * \param logger Logger to which appender will be added
518  * \param target Std target to write 'cout' or 'cerr' (default is cout)
519  * \param pattern Formatting pattern for log messages
520  */
521 GR_RUNTIME_API void
522 logger_add_console_appender(logger_ptr logger, std::string target, std::string pattern);
523 
524 /*!
525  * \brief Sets a new console appender to a given logger after
526  * removing all others. Use logger_add_console_appender to add
527  * another.
528  *
529  * \param logger Logger to which appender will be added
530  * \param target Std target to write 'cout' or 'cerr' (default is cout)
531  * \param pattern Formatting pattern for log messages
532  */
533 GR_RUNTIME_API void
534 logger_set_console_appender(logger_ptr logger, std::string target, std::string pattern);
535 
536 /*!
537  * \brief Add file appender to a given logger
538  *
539  * Add file appender to a given logger
540  *
541  * \param logger Logger to which appender will be added
542  * \param filename File to which log will be written
543  * \param append Overwrite or append to log file
544  * \param pattern Formatting pattern for log messages
545  */
547  std::string filename,
548  bool append,
549  std::string pattern);
550 
551 /*!
552  * \brief Set a file appender to a given logger. To add another file
553  * appender, use logger_add_file_appender.
554  *
555  * \param logger Logger to which appender will be added
556  * \param filename File to which log will be written
557  * \param append Overwrite or append to log file
558  * \param pattern Formatting pattern for log messages
559  */
561  std::string filename,
562  bool append,
563  std::string pattern);
564 
565 /*!
566  * \brief Add rolling file appender to a given logger
567  *
568  * Add rolling file appender to a given logger
569  *
570  * \param logger Logger to which appender will be added
571  * \param filename File to which log will be written
572  * \param filesize Sizez of files to write
573  * \param bkup_index Number of files to write
574  * \param append Overwrite or append to log file
575  * \param mode Permissions to set on log file
576  * \param pattern Formatting pattern for log messages
577  */
579  std::string filename,
580  size_t filesize,
581  int bkup_index,
582  bool append,
583  mode_t mode,
584  std::string pattern);
585 
586 /*!
587  * \brief Add rolling file appender to a given logger
588  *
589  * Add rolling file appender to a given logger
590  *
591  * \return vector of string names of loggers
592  */
593 GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(void);
594 
595 } /* namespace gr */
596 
597 // If Logger disable do nothing
598 namespace gr {
599 
600 /********************* Start Classes and Methods for Python ******************/
601 /*!
602  * \brief Logger class for referencing loggers in python. Not
603  * needed in C++ (use macros) Wraps and manipulates loggers for
604  * python as python has no macros
605  * \ingroup logging
606  *
607  */
609 {
610 private:
611  /*! \brief logger pointer to logger associated wiith this wrapper class */
612  GR_LOG_DECLARE_LOGPTR(d_logger);
613 
614 public:
615  /*!
616  * \brief constructor Provide name of logger to associate with this class
617  * \param logger_name Name of logger associated with class
618  */
619  logger(std::string logger_name) { GR_LOG_ASSIGN_LOGPTR(d_logger, logger_name); };
620 
621  /*! \brief Destructor */
622  ~logger() { ; }
623 
624  // Wrappers for logging macros
625  /*! \brief inline function, wrapper to set the logger level */
626  void set_level(std::string level) { GR_LOG_SET_LEVEL(d_logger, level); }
627 
628  /*! \brief inline function, wrapper to get the logger level */
629  void get_level(std::string& level) { GR_LOG_GET_LEVEL(d_logger, level); }
630 
631  /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
632  void debug(std::string msg) { GR_LOG_DEBUG(d_logger, msg); };
633 
634  /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
635  void info(std::string msg) { GR_LOG_INFO(d_logger, msg); }
636 
637  /*! \brief inline function, wrapper for NOTICE message */
638  void notice(std::string msg) { GR_LOG_NOTICE(d_logger, msg); }
639 
640  /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
641  void warn(std::string msg) { GR_LOG_WARN(d_logger, msg); }
642 
643  /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
644  void error(std::string msg) { GR_LOG_ERROR(d_logger, msg); }
645 
646  /*! \brief inline function, wrapper for NOTICE message */
647  void crit(std::string msg) { GR_LOG_CRIT(d_logger, msg); }
648 
649  /*! \brief inline function, wrapper for ALERT message */
650  void alert(std::string msg) { GR_LOG_ALERT(d_logger, msg); }
651 
652  /*! \brief inline function, wrapper for FATAL message */
653  void fatal(std::string msg) { GR_LOG_FATAL(d_logger, msg); }
654 
655  /*! \brief inline function, wrapper for EMERG message */
656  void emerg(std::string msg) { GR_LOG_EMERG(d_logger, msg); }
657 
658  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
659  */
660  void errorIF(bool cond, std::string msg) { GR_LOG_ERRORIF(d_logger, cond, msg); }
661 
662  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
663  */
664  void log_assert(bool cond, std::string msg) { GR_LOG_ASSERT(d_logger, cond, msg); }
665 
666  /*! \brief inline function, Method to add console appender to logger */
667  void add_console_appender(std::string target, std::string pattern)
668  {
669  GR_LOG_ADD_CONSOLE_APPENDER(d_logger, target, pattern);
670  }
671 
672  /*! \brief inline function, Method to set a console appender to logger */
673  void set_console_appender(std::string target, std::string pattern)
674  {
675  GR_LOG_SET_CONSOLE_APPENDER(d_logger, target, pattern);
676  }
677 
678  /*! \brief inline function, Method to add file appender to logger */
679  void add_file_appender(std::string filename, bool append, std::string pattern)
680  {
681  GR_LOG_ADD_FILE_APPENDER(d_logger, filename, append, pattern);
682  }
683 
684  /*! \brief inline function, Method to set a file appender to logger */
685  void set_file_appender(std::string filename, bool append, std::string pattern)
686  {
687  GR_LOG_SET_FILE_APPENDER(d_logger, filename, append, pattern);
688  }
689 
690  /*! \brief inline function, Method to add rolling file appender to logger */
691  void add_rollingfile_appender(std::string filename,
692  size_t filesize,
693  int bkup_index,
694  bool append,
695  mode_t mode,
696  std::string pattern)
697  {
699  d_logger, filename, filesize, bkup_index, append, mode, pattern);
700  }
701 };
702 
703 } /* namespace gr */
704 
705 /**************** Start Configuration Class and Methods for Python ************/
706 /*!
707  * \brief Function to call configuration macro from python.
708  * Note: Configuration is only updated if filename or watch_period has changed.
709  * \param config_filename Name of configuration file
710  * \param watch_period Seconds to wait between checking for changes in conf file.
711  * Watch_period defaults to 0 in which case the file is not watched for changes
712  */
713 GR_RUNTIME_API void gr_logger_config(const std::string config_filename,
714  unsigned int watch_period = 0);
715 
716 /*!
717  * \brief Function to return logger names to python
718  * \return Vector of name strings
719  *
720  */
721 GR_RUNTIME_API std::vector<std::string> gr_logger_get_logger_names(void);
722 
723 /*!
724  * \brief Function to reset logger configuration from python
725  *
726  */
728 
729 
730 namespace gr {
731 /*!
732  * Function to use the GR prefs files to get and setup the two
733  * default loggers defined there. The loggers are unique to the
734  * class in which they are called, and we pass it the \p name to
735  * identify where the log message originates from. For a GNU Radio
736  * block, we use 'alias()' for this value, and this is set up for us
737  * automatically in gr::block.
738  */
739 GR_RUNTIME_API bool
741 
742 GR_RUNTIME_API bool update_logger_alias(const std::string& name,
743  const std::string& alias);
744 
745 } /* namespace gr */
746 
747 #endif /* INCLUDED_GR_LOGGER_H */
Class to control configuration of logger. This is a singleton that can launch a thread to watch a con...
Definition: logger.h:299
static void reset_config(void)
method to reset logger configuration
static std::string get_filename()
Getter for config filename.
static unsigned int get_watch_period()
Getter for watch period.
static void stop_watch()
Method to stop watcher thread.
~logger_config()
destructor stops watch thread before exits
Definition: logger.h:360
static void load_config(std::string filename, unsigned int watch_period=0)
Method to load configuration /param filename Name of configuration file /param watch_period Seconds b...
Logger class for referencing loggers in python. Not needed in C++ (use macros) Wraps and manipulates ...
Definition: logger.h:609
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:629
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:685
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:638
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:635
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:653
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:664
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:660
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:626
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:632
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:679
~logger()
Destructor.
Definition: logger.h:622
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:647
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:641
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:656
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:691
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:667
void error(std::string msg)
inline function, wrapper for LOG4CPP_ERROR for ERROR message
Definition: logger.h:644
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:673
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:650
logger(std::string logger_name)
constructor Provide name of logger to associate with this class
Definition: logger.h:619
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:98
#define GR_LOG_ADD_ROLLINGFILE_APPENDER( logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:144
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:231
#define GR_LOG_WARN(logger, msg)
Definition: logger.h:246
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:82
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:109
#define GR_LOG_ALERT(logger, msg)
Definition: logger.h:261
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:131
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:241
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:283
GR_RUNTIME_API void gr_logger_reset_config(void)
Function to reset logger configuration from python.
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:236
#define GR_LOG_DECLARE_LOGPTR(logger)
Definition: logger.h:65
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 ...
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:251
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:256
GR_RUNTIME_API std::vector< std::string > gr_logger_get_logger_names(void)
Function to return logger names to python.
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:266
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:276
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:271
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:67
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:90
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:120
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
GR_RUNTIME_API logger_ptr logger_get_logger(std::string name)
Retrieve a pointer to a logger by name.
GR_RUNTIME_API void logger_set_level(logger_ptr logger, const std::string &level)
Set the logger's output level.
GR_RUNTIME_API bool update_logger_alias(const std::string &name, const std::string &alias)
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....
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_reset_config(void)
Reset logger's configuration file.
GR_RUNTIME_API void logger_get_level(logger_ptr logger, std::string &level)
Get the logger's output level.
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.
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
GR_RUNTIME_API void logger_add_appender(logger_ptr logger, std::string appender)
Add console appender to a given logger.
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.
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_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...
GR_RUNTIME_API std::vector< std::string > logger_get_logger_names(void)
Add rolling file appender to a given logger.
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60
GR_RUNTIME_API bool logger_load_config(const std::string &config_filename="")
Load logger's configuration file.