GNU Radio Manual and C++ API Reference  3.9.4.0
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  if (logger->isPriorityEnabled(log4cpp::Priority::DEBUG)) \
163  *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \
164  }
165 
166 #define GR_INFO(name, msg) \
167  { \
168  gr::logger_ptr logger = gr::logger_get_logger(name); \
169  if (logger->isPriorityEnabled(log4cpp::Priority::INFO)) \
170  *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \
171  }
172 
173 #define GR_NOTICE(name, msg) \
174  { \
175  gr::logger_ptr logger = gr::logger_get_logger(name); \
176  if (logger->isPriorityEnabled(log4cpp::Priority::NOTICE)) \
177  *logger << log4cpp::Priority::NOTICE << (msg) << log4cpp::eol; \
178  }
179 
180 #define GR_WARN(name, msg) \
181  { \
182  gr::logger_ptr logger = gr::logger_get_logger(name); \
183  if (logger->isPriorityEnabled(log4cpp::Priority::WARN)) \
184  *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \
185  }
186 
187 #define GR_ERROR(name, msg) \
188  { \
189  gr::logger_ptr logger = gr::logger_get_logger(name); \
190  if (logger->isPriorityEnabled(log4cpp::Priority::ERROR)) \
191  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
192  }
193 
194 #define GR_CRIT(name, msg) \
195  { \
196  gr::logger_ptr logger = gr::logger_get_logger(name); \
197  if (logger->isPriorityEnabled(log4cpp::Priority::CRIT)) \
198  *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \
199  }
200 
201 #define GR_ALERT(name, msg) \
202  { \
203  gr::logger_ptr logger = gr::logger_get_logger(name); \
204  if (logger->isPriorityEnabled(log4cpp::Priority::ALERT)) \
205  *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \
206  }
207 
208 #define GR_FATAL(name, msg) \
209  { \
210  gr::logger_ptr logger = gr::logger_get_logger(name); \
211  if (logger->isPriorityEnabled(log4cpp::Priority::FATAL)) \
212  *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \
213  }
214 
215 #define GR_EMERG(name, msg) \
216  { \
217  gr::logger_ptr logger = gr::logger_get_logger(name); \
218  if (logger->isPriorityEnabled(log4cpp::Priority::EMERG)) \
219  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
220  }
221 
222 #define GR_ERRORIF(name, cond, msg) \
223  { \
224  if ((cond)) { \
225  gr::logger_ptr logger = gr::logger_get_logger(name); \
226  if (logger->isPriorityEnabled(log4cpp::Priority::ERROR)) \
227  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
228  } \
229  }
230 
231 #define GR_ASSERT(name, cond, msg) \
232  { \
233  if (!(cond)) { \
234  gr::logger_ptr logger = gr::logger_get_logger(name); \
235  if (logger->isPriorityEnabled(log4cpp::Priority::EMERG)) \
236  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
237  } \
238  assert(0); \
239  }
240 
241 /* LoggerPtr Referenced Macros */
242 #define GR_LOG_DEBUG(logger, msg) \
243  { \
244  if (logger->isPriorityEnabled(log4cpp::Priority::DEBUG)) \
245  *logger << log4cpp::Priority::DEBUG << (msg) << log4cpp::eol; \
246  }
247 
248 #define GR_LOG_INFO(logger, msg) \
249  { \
250  if (logger->isPriorityEnabled(log4cpp::Priority::INFO)) \
251  *logger << log4cpp::Priority::INFO << (msg) << log4cpp::eol; \
252  }
253 
254 #define GR_LOG_NOTICE(logger, msg) \
255  { \
256  if (logger->isPriorityEnabled(log4cpp::Priority::NOTICE)) \
257  *logger << log4cpp::Priority::NOTICE << (msg) << log4cpp::eol; \
258  }
259 
260 #define GR_LOG_WARN(logger, msg) \
261  { \
262  if (logger->isPriorityEnabled(log4cpp::Priority::WARN)) \
263  *logger << log4cpp::Priority::WARN << (msg) << log4cpp::eol; \
264  }
265 
266 #define GR_LOG_ERROR(logger, msg) \
267  { \
268  if (logger->isPriorityEnabled(log4cpp::Priority::ERROR)) \
269  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
270  }
271 
272 #define GR_LOG_CRIT(logger, msg) \
273  { \
274  if (logger->isPriorityEnabled(log4cpp::Priority::CRIT)) \
275  *logger << log4cpp::Priority::CRIT << (msg) << log4cpp::eol; \
276  }
277 
278 #define GR_LOG_ALERT(logger, msg) \
279  { \
280  if (logger->isPriorityEnabled(log4cpp::Priority::ALERT)) \
281  *logger << log4cpp::Priority::ALERT << (msg) << log4cpp::eol; \
282  }
283 
284 #define GR_LOG_FATAL(logger, msg) \
285  { \
286  if (logger->isPriorityEnabled(log4cpp::Priority::FATAL)) \
287  *logger << log4cpp::Priority::FATAL << (msg) << log4cpp::eol; \
288  }
289 
290 #define GR_LOG_EMERG(logger, msg) \
291  { \
292  if (logger->isPriorityEnabled(log4cpp::Priority::EMERG)) \
293  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
294  }
295 
296 #define GR_LOG_ERRORIF(logger, cond, msg) \
297  { \
298  if ((cond)) { \
299  if (logger->isPriorityEnabled(log4cpp::Priority::ERROR)) \
300  *logger << log4cpp::Priority::ERROR << (msg) << log4cpp::eol; \
301  } \
302  }
303 
304 #define GR_LOG_ASSERT(logger, cond, msg) \
305  { \
306  if (!(cond)) { \
307  if (logger->isPriorityEnabled(log4cpp::Priority::EMERG)) \
308  *logger << log4cpp::Priority::EMERG << (msg) << log4cpp::eol; \
309  assert(0); \
310  } \
311  }
312 
313 namespace gr {
314 
315 /*!
316  * \brief Class to control configuration of logger.
317  * This is a singleton that can launch a thread to watch a config file for changes
318  * \ingroup logging
319  */
321 {
322 private:
323  /*! \brief filename of logger config file */
324  std::string filename;
325  /*! \brief Period (seconds) over which watcher thread checks config file for changes
326  */
327  unsigned int watch_period;
328  /*! \brief watch thread for config file changes */
329  std::unique_ptr<boost::thread> watch_thread;
330 
331  /*! \brief Watcher thread method
332  * /param filename Name of configuration file
333  * /param watch_period Seconds between checks for changes in config file
334  */
335  static void watch_file(std::string filename, unsigned int watch_period);
336 
337  static bool logger_configured;
338 
339  logger_config() /*:
340  rpc_get_filename("logger_config", "filename", &logger_config::get_filename4rpc,
341  pmt::mp(""), pmt::mp(""), pmt::mp(""),
342  "", "filename", RPC_PRIVLVL_MIN,
343  DISPTIME | DISPOPTSTRIP),
344  rpc_get_watchperiod("logger_config", "watch_period",
345  &logger_config::get_watchperiod4rpc, pmt::mp(0), pmt::mp(32768), pmt::mp(0),
346  "", "watch_period", RPC_PRIVLVL_MIN,
347  DISPTIME | DISPOPTSTRIP),
348  rpc_get_config("logger_config", "config", &logger_config::get_config4rpc,
349  pmt::mp(""), pmt::mp(""), pmt::mp(""),
350  "", "filename", RPC_PRIVLVL_MIN,
351  DISPTIME | DISPOPTSTRIP),
352  rpc_set_config("logger_config","config", &logger_config::set_config4rpc,
353  pmt::mp(""), pmt::mp(""), pmt::mp(""),
354  "", "filename", RPC_PRIVLVL_MIN,
355  DISPTIME | DISPOPTSTRIP)
356  */
357  {
358  } //!< Constructor
359 
360  /*
361  rpcbasic_register_get<logger_config,std::string> rpc_get_filename;
362  rpcbasic_register_get<logger_config,int> rpc_get_watchperiod;
363  rpcbasic_register_get<logger_config,std::string> rpc_get_config;
364  rpcbasic_register_set<logger_config,std::string> rpc_set_config;
365  */
366 
367  logger_config(logger_config const&); //!< Copy constructor
368  void operator=(logger_config const&); //!< Assignment Operator
369 
370  std::string get_filename4rpc() { return filename; }
371  int get_watchperiod4rpc() { return watch_period; };
372 
373  std::string get_config4rpc() { return filename; }
374 
375  void set_config4rpc(std::string set) { printf("Set string was:%s\n", set.c_str()); }
376 
377  /*! \brief Instance getter for singleton. Only used by class. */
378  static logger_config& get_instance(void);
379 
380 public:
381  /*! \brief destructor stops watch thread before exits */
382  ~logger_config() { stop_watch(); }
383  /*! \brief Getter for config filename */
384  static std::string get_filename();
385  /*! \brief Getter for watch period */
386  static unsigned int get_watch_period();
387  /*! \brief Method to load configuration
388  * /param filename Name of configuration file
389  * /param watch_period Seconds between checks for changes in config file
390  */
391  static void load_config(std::string filename, unsigned int watch_period = 0);
392  /*! \brief Method to stop watcher thread */
393  static void stop_watch();
394  /*! \brief method to reset logger configuration */
395  static void reset_config(void);
396 };
397 
398 /*!
399  * \brief Retrieve a pointer to a logger by name
400  *
401  * Retrieves a logger pointer
402  * \p name.
403  *
404  * \param name Name of the logger for which a pointer is requested
405  */
407 
408 /*!
409  * \brief Load logger's configuration file.
410  *
411  * Initialize the GNU Radio logger by loading the configuration file
412  * \p config_filename.
413  *
414  * \param config_filename The configuration file. Set to "" for the
415  * basic logger that outputs to the console.
416  */
417 GR_RUNTIME_API bool logger_load_config(const std::string& config_filename = "");
418 
419 /*!
420  * \brief Reset logger's configuration file.
421  *
422  * Remove all appenders from loggers
423  */
425 
426 /*!
427  * \brief Set the logger's output level.
428  *
429  * Sets the level of the logger. This takes a string that is
430  * translated to the standard levels and can be (case insensitive):
431  *
432  * \li off , notset
433  * \li debug
434  * \li info
435  * \li notice
436  * \li warn
437  * \li error
438  * \li crit
439  * \li alert
440  * \li fatal
441  * \li emerg
442  *
443  * \param logger the logger to set the level of.
444  * \param level string to set the level to.
445  */
446 GR_RUNTIME_API void logger_set_level(logger_ptr logger, const std::string& level);
447 
448 /*!
449  * \brief Set the logger's output level.
450  *
451  * Sets the level of the logger. This takes the actual Log4cpp::Priority
452  * data type, which can be:
453  *
454  * \li log4cpp::Priority::NOTSET
455  * \li log4cpp::Priority::DEBUG
456  * \li log4cpp::Priority::INFO
457  * \li log4cpp::Priority::NOTICE
458  * \li log4cpp::Priority::WARN
459  * \li log4cpp::Priority::ERROR
460  * \li log4cpp::Priority::CRIT
461  * \li log4cpp::Priority::ALERT
462  * \li log4cpp::Priority::FATAL
463  * \li log4cpp::Priority::EMERG
464  *
465  * \param logger the logger to set the level of.
466  * \param level new logger level of type Log4cpp::Priority
467  */
468 GR_RUNTIME_API void logger_set_level(logger_ptr logger, log4cpp::Priority::Value level);
469 
470 /*!
471  * \brief Get the logger's output level.
472  *
473  * Gets the level of the logger. This returns a string that
474  * corresponds to the standard levels and can be (case insensitive):
475  *
476  * \li notset
477  * \li debug
478  * \li info
479  * \li notice
480  * \li warn
481  * \li error
482  * \li crit
483  * \li alert
484  * \li fatal
485  * \li emerg
486  *
487  * \param logger the logger to get the level of.
488  * \param level string to get the level into.
489  */
491 
492 /*!
493  * \brief Get the logger's output level.
494  *
495  * Gets the level of the logger. This returns the actual Log4cpp::Level
496  * data type, which can be:
497  *
498  * \li log4cpp::Priority::NOTSET
499  * \li log4cpp::Priority::DEBUG
500  * \li log4cpp::Priority::INFO
501  * \li log4cpp::Priority::NOTICE
502  * \li log4cpp::Priority::WARN
503  * \li log4cpp::Priority::ERROR
504  * \li log4cpp::Priority::CRIT
505  * \li log4cpp::Priority::ALERT
506  * \li log4cpp::Priority::FATAL
507  * \li log4cpp::Priority::EMERG
508  *
509  * \param logger the logger to get the level of.
510  * \param level of the logger.
511  */
512 GR_RUNTIME_API void logger_get_level(logger_ptr logger, log4cpp::Priority::Value& level);
513 
514 /*!
515  * \brief Add console appender to a given logger
516  *
517  * Add console appender to a given logger
518  *
519  * \param logger Logger to which appender will be added
520  * \param appender Name of appender to add to logger
521  */
523 
524 /*!
525  * \brief Sets a console appender to a given logger. Deletes any
526  * existing appenders and adds a new one. To add an additional
527  * appender, use logger_add_appender.
528  *
529  * \param logger Logger to which appender will be added
530  * \param appender Name of appender to add to logger
531  */
533 
534 /*!
535  * \brief Add console appender to a given logger
536  *
537  * Add console appender to a given logger
538  *
539  * \param logger Logger to which appender will be added
540  * \param target Std target to write 'cout' or 'cerr' (default is cout)
541  * \param pattern Formatting pattern for log messages
542  */
543 GR_RUNTIME_API void
544 logger_add_console_appender(logger_ptr logger, std::string target, std::string pattern);
545 
546 /*!
547  * \brief Sets a new console appender to a given logger after
548  * removing all others. Use logger_add_console_appender to add
549  * another.
550  *
551  * \param logger Logger to which appender will be added
552  * \param target Std target to write 'cout' or 'cerr' (default is cout)
553  * \param pattern Formatting pattern for log messages
554  */
555 GR_RUNTIME_API void
556 logger_set_console_appender(logger_ptr logger, std::string target, std::string pattern);
557 
558 /*!
559  * \brief Add file appender to a given logger
560  *
561  * Add file appender to a given logger
562  *
563  * \param logger Logger to which appender will be added
564  * \param filename File to which log will be written
565  * \param append Overwrite or append to log file
566  * \param pattern Formatting pattern for log messages
567  */
569  std::string filename,
570  bool append,
571  std::string pattern);
572 
573 /*!
574  * \brief Set a file appender to a given logger. To add another file
575  * appender, use logger_add_file_appender.
576  *
577  * \param logger Logger to which appender will be added
578  * \param filename File to which log will be written
579  * \param append Overwrite or append to log file
580  * \param pattern Formatting pattern for log messages
581  */
583  std::string filename,
584  bool append,
585  std::string pattern);
586 
587 /*!
588  * \brief Add rolling file appender to a given logger
589  *
590  * Add rolling file appender to a given logger
591  *
592  * \param logger Logger to which appender will be added
593  * \param filename File to which log will be written
594  * \param filesize Sizez of files to write
595  * \param bkup_index Number of files to write
596  * \param append Overwrite or append to log file
597  * \param mode Permissions to set on log file
598  * \param pattern Formatting pattern for log messages
599  */
601  std::string filename,
602  size_t filesize,
603  int bkup_index,
604  bool append,
605  mode_t mode,
606  std::string pattern);
607 
608 /*!
609  * \brief Add rolling file appender to a given logger
610  *
611  * Add rolling file appender to a given logger
612  *
613  * \return vector of string names of loggers
614  */
615 GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(void);
616 
617 } /* namespace gr */
618 
619 // If Logger disable do nothing
620 namespace gr {
621 
622 /********************* Start Classes and Methods for Python ******************/
623 /*!
624  * \brief Logger class for referencing loggers in python. Not
625  * needed in C++ (use macros) Wraps and manipulates loggers for
626  * python as python has no macros
627  * \ingroup logging
628  *
629  */
631 {
632 private:
633  /*! \brief logger pointer to logger associated wiith this wrapper class */
634  GR_LOG_DECLARE_LOGPTR(d_logger);
635 
636 public:
637  /*!
638  * \brief constructor Provide name of logger to associate with this class
639  * \param logger_name Name of logger associated with class
640  */
641  logger(std::string logger_name) { GR_LOG_ASSIGN_LOGPTR(d_logger, logger_name); };
642 
643  /*! \brief Destructor */
644  ~logger() { ; }
645 
646  // Wrappers for logging macros
647  /*! \brief inline function, wrapper to set the logger level */
648  void set_level(std::string level) { GR_LOG_SET_LEVEL(d_logger, level); }
649 
650  /*! \brief inline function, wrapper to get the logger level */
651  void get_level(std::string& level) { GR_LOG_GET_LEVEL(d_logger, level); }
652 
653  /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
654  void debug(std::string msg) { GR_LOG_DEBUG(d_logger, msg); };
655 
656  /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
657  void info(std::string msg) { GR_LOG_INFO(d_logger, msg); }
658 
659  /*! \brief inline function, wrapper for NOTICE message */
660  void notice(std::string msg) { GR_LOG_NOTICE(d_logger, msg); }
661 
662  /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
663  void warn(std::string msg) { GR_LOG_WARN(d_logger, msg); }
664 
665  /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
666  void error(std::string msg) { GR_LOG_ERROR(d_logger, msg); }
667 
668  /*! \brief inline function, wrapper for NOTICE message */
669  void crit(std::string msg) { GR_LOG_CRIT(d_logger, msg); }
670 
671  /*! \brief inline function, wrapper for ALERT message */
672  void alert(std::string msg) { GR_LOG_ALERT(d_logger, msg); }
673 
674  /*! \brief inline function, wrapper for FATAL message */
675  void fatal(std::string msg) { GR_LOG_FATAL(d_logger, msg); }
676 
677  /*! \brief inline function, wrapper for EMERG message */
678  void emerg(std::string msg) { GR_LOG_EMERG(d_logger, msg); }
679 
680  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
681  */
682  void errorIF(bool cond, std::string msg) { GR_LOG_ERRORIF(d_logger, cond, msg); }
683 
684  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
685  */
686  void log_assert(bool cond, std::string msg) { GR_LOG_ASSERT(d_logger, cond, msg); }
687 
688  /*! \brief inline function, Method to add console appender to logger */
689  void add_console_appender(std::string target, std::string pattern)
690  {
691  GR_LOG_ADD_CONSOLE_APPENDER(d_logger, target, pattern);
692  }
693 
694  /*! \brief inline function, Method to set a console appender to logger */
695  void set_console_appender(std::string target, std::string pattern)
696  {
697  GR_LOG_SET_CONSOLE_APPENDER(d_logger, target, pattern);
698  }
699 
700  /*! \brief inline function, Method to add file appender to logger */
701  void add_file_appender(std::string filename, bool append, std::string pattern)
702  {
703  GR_LOG_ADD_FILE_APPENDER(d_logger, filename, append, pattern);
704  }
705 
706  /*! \brief inline function, Method to set a file appender to logger */
707  void set_file_appender(std::string filename, bool append, std::string pattern)
708  {
709  GR_LOG_SET_FILE_APPENDER(d_logger, filename, append, pattern);
710  }
711 
712  /*! \brief inline function, Method to add rolling file appender to logger */
713  void add_rollingfile_appender(std::string filename,
714  size_t filesize,
715  int bkup_index,
716  bool append,
717  mode_t mode,
718  std::string pattern)
719  {
721  d_logger, filename, filesize, 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 
752 namespace gr {
753 /*!
754  * Function to use the GR prefs files to get and setup the two
755  * default loggers defined there. The loggers are unique to the
756  * class in which they are called, and we pass it the \p name to
757  * identify where the log message originates from. For a GNU Radio
758  * block, we use 'alias()' for this value, and this is set up for us
759  * automatically in gr::block.
760  */
761 GR_RUNTIME_API bool
763 
764 GR_RUNTIME_API bool update_logger_alias(const std::string& name,
765  const std::string& alias);
766 
767 } /* namespace gr */
768 
769 #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:321
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:382
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:631
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:651
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:707
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:660
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:657
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:675
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:686
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:682
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:648
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:654
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:701
~logger()
Destructor.
Definition: logger.h:644
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:669
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:663
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:678
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:713
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:689
void error(std::string msg)
inline function, wrapper for LOG4CPP_ERROR for ERROR message
Definition: logger.h:666
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:695
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:672
logger(std::string logger_name)
constructor Provide name of logger to associate with this class
Definition: logger.h:641
#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:242
#define GR_LOG_WARN(logger, msg)
Definition: logger.h:260
#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:278
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:131
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:254
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:304
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:248
#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:266
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:272
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:284
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:296
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:290
#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.