GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_SET_APPENDER(name,appender)
80 #define GR_LOG_SET_APPENDER(logger,appender)
81 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
82 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
83 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
84 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
85 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
86 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
87 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
88 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
89 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
90 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
91 #define GR_GET_LOGGER_NAMES(names)
92 #define GR_RESET_CONFIGURATION()
93 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
94 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
95 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
96 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
97 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
98 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
99 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
100 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
101 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
102 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
103 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
104 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
105 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
106 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
107 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
108 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
109 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
110 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
111 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
112 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
113 #define GR_LOG_ERRORIF(logger, cond, msg) { \
114  if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
115 #define GR_LOG_ASSERT(logger, cond, msg) { \
116  if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
117 
118 
119 #else /* HAVE_LOG4CPP */
120 
121 // Second configuration...logging to log4cpp
122 #include <log4cpp/Category.hh>
123 #include <log4cpp/PropertyConfigurator.hh>
124 #include <log4cpp/FileAppender.hh>
125 #include <log4cpp/RollingFileAppender.hh>
126 #include <log4cpp/OstreamAppender.hh>
127 #include <log4cpp/PatternLayout.hh>
128 
129 namespace gr {
130 
131  /*!
132  * \brief GR_LOG macros
133  * \ingroup logging
134  *
135  * These macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros
136  * are:
137  * LOG_DEBUG
138  * LOG_INFO
139  * LOG_WARN
140  * LOG_TRACE
141  * LOG_ERROR
142  * LOG_ALERT
143  * LOG_CRIT
144  * LOG_FATAL
145  * LOG_EMERG
146  */
147  typedef log4cpp::Category* logger_ptr;
148 
149 } /* namespace gr */
150 
151 
152  /* Macros for Programmatic Configuration */
153 #define GR_LOG_DECLARE_LOGPTR(logger) \
154  gr::logger_ptr logger;
155 
156 #define GR_LOG_ASSIGN_LOGPTR(logger,name) \
157  logger = gr::logger_get_logger(name);
158 
159 #define GR_CONFIG_LOGGER(config) \
160  gr::logger_config::load_config(config)
161 
162 #define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
163  gr::logger_config::load_config(config,period)
164 
165 #define GR_LOG_GETLOGGER(logger, name) \
166  gr::logger_ptr logger = gr::logger_get_logger(name);
167 
168 #define GR_SET_LEVEL(name, level) { \
169  gr::logger_ptr logger = gr::logger_get_logger(name); \
170  gr::logger_set_level(logger,level);}
171 
172 #define GR_LOG_SET_LEVEL(logger, level) \
173  gr::logger_set_level(logger, level);
174 
175 #define GR_GET_LEVEL(name, level) { \
176  gr::logger_ptr logger = gr::logger_get_logger(name); \
177  gr::logger_get_level(logger,level);}
178 
179 #define GR_LOG_GET_LEVEL(logger, level) \
180  gr::logger_get_level(logger,level);
181 
182 #define GR_ADD_APPENDER(name, appender) { \
183  gr::logger_ptr logger = gr::logger_get_logger(name); \
184  gr::logger_add_appender(logger,appender);}
185 
186 #define GR_LOG_ADD_APPENDER(logger, appender) { \
187  gr::logger_add_appender(logger, appender);}
188 
189 #define GR_SET_APPENDER(name, appender) { \
190  gr::logger_ptr logger = gr::logger_get_logger(name); \
191  gr::logger_set_appender(logger,appender);}
192 
193 #define GR_LOG_SET_APPENDER(logger, appender) { \
194  gr::logger_set_appender(logger, appender);}
195 
196 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) { \
197  gr::logger_ptr logger = gr::logger_get_logger(name); \
198  gr::logger_add_console_appender(logger,target,pattern);}
199 
200 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) { \
201  gr::logger_add_console_appender(logger,target,pattern);}
202 
203 #define GR_SET_CONSOLE_APPENDER(name, target, pattern) { \
204  gr::logger_ptr logger = gr::logger_get_logger(name); \
205  gr::logger_set_console_appender(logger,target,pattern);}
206 
207 #define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern) { \
208  gr::logger_set_console_appender(logger,target,pattern);}
209 
210 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) { \
211  gr::logger_ptr logger = gr::logger_get_logger(name); \
212  gr::logger_add_file_appender(logger,filename,append,pattern);}
213 
214 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) { \
215  gr::logger_add_file_appender(logger,filename,append,pattern);}
216 
217 #define GR_SET_FILE_APPENDER(name, filename, append, pattern) { \
218  gr::logger_ptr logger = gr::logger_get_logger(name); \
219  gr::logger_set_file_appender(logger,filename,append,pattern);}
220 
221 #define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern) { \
222  gr::logger_set_file_appender(logger,filename,append,pattern);}
223 
224 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \
225  gr::logger_ptr logger = gr::logger_get_logger(name); \
226  gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
227 
228 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \
229  gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
230 
231 #define GR_GET_LOGGER_NAMES(names) { \
232  names = gr::logger_get_logger_names();}
233 
234 #define GR_RESET_CONFIGURATION() \
235  gr::logger_config::reset_config();
236 
237  /* Logger name referenced macros */
238 #define GR_DEBUG(name, msg) { \
239  gr::logger_ptr logger = gr::logger_get_logger(name); \
240  *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
241 
242 #define GR_INFO(name, msg) { \
243  gr::logger_ptr logger = gr::logger_get_logger(name); \
244  *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
245 
246 #define GR_NOTICE(name, msg) { \
247  gr::logger_ptr logger = gr::logger_get_logger(name); \
248  *logger << log4cpp::Priority::NOTICE << msg;}
249 
250 #define GR_WARN(name, msg) { \
251  gr::logger_ptr logger = gr::logger_get_logger(name); \
252  *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
253 
254 #define GR_ERROR(name, msg) { \
255  gr::logger_ptr logger = gr::logger_get_logger(name); \
256  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
257 
258 #define GR_CRIT(name, msg) { \
259  gr::logger_ptr logger = gr::logger_get_logger(name); \
260  *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
261 
262 #define GR_ALERT(name, msg) { \
263  gr::logger_ptr logger = gr::logger_get_logger(name); \
264  *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
265 
266 #define GR_FATAL(name, msg) { \
267  gr::logger_ptr logger = gr::logger_get_logger(name); \
268  *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
269 
270 #define GR_EMERG(name, msg) { \
271  gr::logger_ptr logger = gr::logger_get_logger(name); \
272  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
273 
274 #define GR_ERRORIF(name, cond, msg) { \
275  if((cond)) { \
276  gr::logger_ptr logger = gr::logger_get_logger(name); \
277  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
278  }
279 
280 #define GR_ASSERT(name, cond, msg) { \
281  if(!(cond)) { \
282  gr::logger_ptr logger = gr::logger_get_logger(name); \
283  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;} \
284  assert(0); \
285  }
286 
287  /* LoggerPtr Referenced Macros */
288 #define GR_LOG_DEBUG(logger, msg) { \
289  *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
290 
291 #define GR_LOG_INFO(logger, msg) { \
292  *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
293 
294 #define GR_LOG_NOTICE(logger, msg) { \
295  *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
296 
297 #define GR_LOG_WARN(logger, msg) { \
298  *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
299 
300 #define GR_LOG_ERROR(logger, msg) { \
301  *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
302 
303 #define GR_LOG_CRIT(logger, msg) { \
304  *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
305 
306 #define GR_LOG_ALERT(logger, msg) { \
307  *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
308 
309 #define GR_LOG_FATAL(logger, msg) { \
310  *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
311 
312 #define GR_LOG_EMERG(logger, msg) { \
313  *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
314 
315 #define GR_LOG_ERRORIF(logger,cond, msg) { \
316  if((cond)) { \
317  *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;} \
318  }
319 
320 #define GR_LOG_ASSERT(logger, cond, msg) { \
321  if(!(cond)) { \
322  *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
323  assert(0);} \
324  }
325 
326 namespace gr {
327 
328  /*!
329  * \brief Class to control configuration of logger.
330  * This is a singleton that cna launch a thread to wathc a config file for changes
331  * \ingroup logging
332  */
333  class GR_RUNTIME_API logger_config
334  {
335  private:
336  /*! \brief filename of logger config file */
337  std::string filename;
338  /*! \brief Period (seconds) over which watcher thread checks config file for changes */
339  unsigned int watch_period;
340  /*! \brief Pointer to watch thread for config file changes */
341  boost::thread *watch_thread;
342 
343  /*! \brief Watcher thread method
344  * /param filename Name of configuration file
345  * /param watch_period Seconds between checks for changes in config file
346  */
347  static void watch_file(std::string filename,unsigned int watch_period);
348 
349  static bool logger_configured;
350 
351  logger_config()/*:
352  rpc_get_filename("logger_config", "filename", &logger_config::get_filename4rpc,
353  pmt::mp(""), pmt::mp(""), pmt::mp(""),
354  "", "filename", RPC_PRIVLVL_MIN,
355  DISPTIME | DISPOPTSTRIP),
356  rpc_get_watchperiod("logger_config", "watch_period", &logger_config::get_watchperiod4rpc,
357  pmt::mp(0), pmt::mp(32768), pmt::mp(0),
358  "", "watch_period", RPC_PRIVLVL_MIN,
359  DISPTIME | DISPOPTSTRIP),
360  rpc_get_config("logger_config", "config", &logger_config::get_config4rpc,
361  pmt::mp(""), pmt::mp(""), pmt::mp(""),
362  "", "filename", RPC_PRIVLVL_MIN,
363  DISPTIME | DISPOPTSTRIP),
364  rpc_set_config("logger_config","config", &logger_config::set_config4rpc,
365  pmt::mp(""), pmt::mp(""), pmt::mp(""),
366  "", "filename", RPC_PRIVLVL_MIN,
367  DISPTIME | DISPOPTSTRIP)
368  */
369  {
370  } //!< Constructor
371 
372  /*
373  rpcbasic_register_get<logger_config,std::string> rpc_get_filename;
374  rpcbasic_register_get<logger_config,int> rpc_get_watchperiod;
375  rpcbasic_register_get<logger_config,std::string> rpc_get_config;
376  rpcbasic_register_set<logger_config,std::string> rpc_set_config;
377  */
378 
379  logger_config(logger_config const&); //!<Copy constructor
380  void operator=(logger_config const&); //!<Assignment Operator
381 
382  std::string get_filename4rpc() {
383  return filename;
384  }
385  int get_watchperiod4rpc(){return watch_period;};
386 
387  std::string get_config4rpc() {
388  return filename;
389  }
390 
391  void set_config4rpc(std::string set) {
392  printf("Set string was:%s\n", set.c_str());
393  }
394 
395  /*! \brief destrcutor stops watch thread before exits */
396  ~logger_config() {
397  stop_watch();
398  }
399 
400  /*! \brief Instance getter for singleton. Only used by class. */
401  static logger_config& get_instance(void);
402 
403  public:
404  /*! \brief Getter for config filename */
405  static std::string get_filename();
406  /*! \brief Getter for watch period */
407  static unsigned int get_watch_period();
408  /*! \brief Method to load configuration
409  * /param filename Name of configuration file
410  * /param watch_period Seconds between checks for changes in config file
411  */
412  static void load_config(std::string filename,unsigned int watch_period=0);
413  /*! \brief Method to stop watcher thread */
414  static void stop_watch();
415  /*! \brief method to reset logger configuration */
416  static void reset_config(void);
417  };
418 
419  /*!
420  * \brief Retrieve a pointer to a logger by name
421  *
422  * Retrives a logger pointer
423  * \p name.
424  *
425  * \param name Name of the logger for which a pointer is requested
426  */
427  GR_RUNTIME_API logger_ptr logger_get_logger(std::string name);
428 
429  /*!
430  * \brief Load logger's configuration file.
431  *
432  * Initialize the GNU Radio logger by loading the configuration file
433  * \p config_filename.
434  *
435  * \param config_filename The configuration file. Set to "" for the
436  * basic logger that outputs to the console.
437  */
438  GR_RUNTIME_API bool logger_load_config(const std::string &config_filename="");
439 
440  /*!
441  * \brief Reset logger's configuration file.
442  *
443  * Remove all appenders from loggers
444  */
445  GR_RUNTIME_API void logger_reset_config(void);
446 
447  /*!
448  * \brief Set the logger's output level.
449  *
450  * Sets the level of the logger. This takes a string that is
451  * translated to the standard levels and can be (case insensitive):
452  *
453  * \li off , notset
454  * \li debug
455  * \li info
456  * \li notice
457  * \li warn
458  * \li error
459  * \li crit
460  * \li alert
461  * \li fatal
462  * \li emerg
463  *
464  * \param logger the logger to set the level of.
465  * \param level string to set the level to.
466  */
467  GR_RUNTIME_API void logger_set_level(logger_ptr logger,
468  const std::string &level);
469 
470  /*!
471  * \brief Set the logger's output level.
472  *
473  * Sets the level of the logger. This takes the actual Log4cpp::Priority
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 set the level of.
488  * \param level new logger level of type Log4cpp::Priority
489  */
490  GR_RUNTIME_API void logger_set_level(logger_ptr logger,
491  log4cpp::Priority::Value level);
492 
493  /*!
494  * \brief Get the logger's output level.
495  *
496  * Gets the level of the logger. This returns a string that
497  * corresponds to the standard levels and can be (case insensitive):
498  *
499  * \li notset
500  * \li debug
501  * \li info
502  * \li notice
503  * \li warn
504  * \li error
505  * \li crit
506  * \li alert
507  * \li fatal
508  * \li emerg
509  *
510  * \param logger the logger to get the level of.
511  * \param level string to get the level into.
512  */
513  GR_RUNTIME_API void logger_get_level(logger_ptr logger, std::string &level);
514 
515  /*!
516  * \brief Get the logger's output level.
517  *
518  * Gets the level of the logger. This returns the actual Log4cpp::Level
519  * data type, which can be:
520  *
521  * \li log4cpp::Priority::NOTSET
522  * \li log4cpp::Priority::DEBUG
523  * \li log4cpp::Priority::INFO
524  * \li log4cpp::Priority::NOTICE
525  * \li log4cpp::Priority::WARN
526  * \li log4cpp::Priority::ERROR
527  * \li log4cpp::Priority::CRIT
528  * \li log4cpp::Priority::ALERT
529  * \li log4cpp::Priority::FATAL
530  * \li log4cpp::Priority::EMERG
531  *
532  * \param logger the logger to get the level of.
533  * \param level of the logger.
534  */
535  GR_RUNTIME_API void logger_get_level(logger_ptr logger,
536  log4cpp::Priority::Value &level);
537 
538  /*!
539  * \brief Add console appender to a given logger
540  *
541  * Add console appender to a given logger
542  *
543  * \param logger Logger to which appender will be added
544  * \param appender Name of appender to add to logger
545  */
546  GR_RUNTIME_API void logger_add_appender(logger_ptr logger,
547  std::string appender);
548 
549  /*!
550  * \brief Sets a console appender to a given logger. Deletes any
551  * existing appenders and adds a new one. To add an additional
552  * appender, use logger_add_appender.
553  *
554  * \param logger Logger to which appender will be added
555  * \param appender Name of appender to add to logger
556  */
557  GR_RUNTIME_API void logger_set_appender(logger_ptr logger,
558  std::string appender);
559 
560  /*!
561  * \brief Add console appender to a given logger
562  *
563  * Add console appender to a given logger
564  *
565  * \param logger Logger to which appender will be added
566  * \param target Std target to write 'cout' or 'cerr' (default is cout)
567  * \param pattern Formating pattern for log messages
568  */
569  GR_RUNTIME_API void logger_add_console_appender(logger_ptr logger,
570  std::string target,
571  std::string pattern);
572 
573  /*!
574  * \brief Sets a new console appender to a given logger after
575  * removing all others. Use logger_add_console_appender to add
576  * another.
577  *
578  * \param logger Logger to which appender will be added
579  * \param target Std target to write 'cout' or 'cerr' (default is cout)
580  * \param pattern Formating pattern for log messages
581  */
582  GR_RUNTIME_API void logger_set_console_appender(logger_ptr logger,
583  std::string target,
584  std::string pattern);
585 
586  /*!
587  * \brief Add file appender to a given logger
588  *
589  * Add file appender to a given logger
590  *
591  * \param logger Logger to which appender will be added
592  * \param filename File to which log will be written
593  * \param append Overwrite or append to log file
594  * \param pattern Formating pattern for log messages
595  */
596  GR_RUNTIME_API void logger_add_file_appender(logger_ptr logger,
597  std::string filename,
598  bool append, std::string pattern);
599 
600  /*!
601  * \brief Set a file appender to a given logger. To add another file
602  * appender, use logger_add_file_appender.
603  *
604  * \param logger Logger to which appender will be added
605  * \param filename File to which log will be written
606  * \param append Overwrite or append to log file
607  * \param pattern Formating pattern for log messages
608  */
609  GR_RUNTIME_API void logger_set_file_appender(logger_ptr logger,
610  std::string filename,
611  bool append, std::string pattern);
612 
613  /*!
614  * \brief Add rolling file appender to a given logger
615  *
616  * Add rolling file appender to a given logger
617  *
618  * \param logger Logger to which appender will be added
619  * \param filename File to which log will be written
620  * \param filesize Sizez of files to write
621  * \param bkup_index Number of files to write
622  * \param append Overwrite or append to log file
623  * \param mode Permissions to set on log file
624  * \param pattern Formating pattern for log messages
625  */
626  GR_RUNTIME_API void logger_add_rollingfile_appender(logger_ptr logger, std::string filename,
627  size_t filesize, int bkup_index, bool append,
628  mode_t mode,std::string pattern);
629 
630  /*!
631  * \brief Add rolling file appender to a given logger
632  *
633  * Add rolling file appender to a given logger
634  *
635  * \return vector of string names of loggers
636  */
637  GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(void);
638 
639 } /* namespace gr */
640 
641 #endif /* HAVE_LOG4CPP */
642 
643  // If Logger disable do nothing
644 #else /* ENABLE_GR_LOG */
645 
646 namespace gr {
647  typedef void* logger_ptr;
648 } /* namespace gr */
649 
650 #define GR_LOG_DECLARE_LOGPTR(logger)
651 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
652 #define GR_CONFIG_LOGGER(config)
653 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
654 #define GR_LOG_GETLOGGER(logger, name)
655 #define GR_SET_LEVEL(name, level)
656 #define GR_LOG_SET_LEVEL(logger, level)
657 #define GR_GET_LEVEL(name, level)
658 #define GR_LOG_GET_LEVEL(logger, level)
659 #define GR_ADD_APPENDER(name,appender)
660 #define GR_LOG_ADD_APPENDER(logger,appender)
661 #define GR_SET_APPENDER(name,appender)
662 #define GR_LOG_SET_APPENDER(logger,appender)
663 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
664 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
665 #define GR_SET_CONSOLE_APPENDER(logger,target,pattern)
666 #define GR_LOG_SET_CONSOLE_APPENDER(logger,target,pattern)
667 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
668 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
669 #define GR_SET_FILE_APPENDER(name,filename,append,pattern)
670 #define GR_LOG_SET_FILE_APPENDER(logger,filename,append,pattern)
671 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
672 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
673 #define GR_GET_LOGGER_NAMES(names)
674 #define GR_RESET_CONFIGURATION()
675 #define GR_DEBUG(name, msg)
676 #define GR_INFO(name, msg)
677 #define GR_NOTICE(name, msg)
678 #define GR_WARN(name, msg)
679 #define GR_ERROR(name, msg)
680 #define GR_ALERT(name, msg)
681 #define GR_CRIT(name, msg)
682 #define GR_FATAL(name, msg)
683 #define GR_EMERG(name, msg)
684 #define GR_ERRORIF(name, cond, msg)
685 #define GR_ASSERT(name, cond, msg)
686 #define GR_LOG_DEBUG(logger, msg)
687 #define GR_LOG_INFO(logger, msg)
688 #define GR_LOG_NOTICE(logger, msg)
689 #define GR_LOG_WARN(logger, msg)
690 #define GR_LOG_ERROR(logger, msg)
691 #define GR_LOG_ALERT(logger, msg)
692 #define GR_LOG_CRIT(logger, msg)
693 #define GR_LOG_FATAL(logger, msg)
694 #define GR_LOG_EMERG(logger, msg)
695 #define GR_LOG_ERRORIF(logger, cond, msg)
696 #define GR_LOG_ASSERT(logger, cond, msg)
697 
698 #endif /* ENABLE_GR_LOG */
699 
700 namespace gr {
701 
702  // Even if logger is disabled we'll need for methods below to exist in python.
703  // The macros these call will be disabled if ENABLE_GR_LOG is undefined
704 
705  /********************* Start Classes and Methods for Python ******************/
706  /*!
707  * \brief Logger class for referencing loggers in python. Not
708  * needed in C++ (use macros) Wraps and manipulates loggers for
709  * python as python has no macros
710  * \ingroup logging
711  *
712  */
714  {
715  private:
716  /*! \brief logger pointer to logger associated wiith this wrapper class */
717  logger_ptr d_logger;
718  public:
719  /*!
720  * \brief contructor Provide name of logger to associate with this class
721  * \param logger_name Name of logger associated with class
722  */
723  logger(std::string logger_name) {
724  GR_LOG_ASSIGN_LOGPTR(d_logger,logger_name);
725  };
726 
727  /*! \brief Destructor */
728  ~logger(){;}
729 
730  // Wrappers for logging macros
731  /*! \brief inline function, wrapper to set the logger level */
732  void set_level(std::string level){GR_LOG_SET_LEVEL(d_logger,level);}
733 
734  /*! \brief inline function, wrapper to get the logger level */
735  void get_level(std::string &level){GR_LOG_GET_LEVEL(d_logger,level);}
736 
737  /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
738  void debug(std::string msg){GR_LOG_DEBUG(d_logger,msg);};
739 
740  /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
741  void info(std::string msg){GR_LOG_INFO(d_logger,msg);}
742 
743  /*! \brief inline function, wrapper for NOTICE message */
744  void notice(std::string msg){GR_LOG_NOTICE(d_logger,msg);}
745 
746  /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
747  void warn(std::string msg){GR_LOG_WARN(d_logger,msg);}
748 
749  /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
750  void error(std::string msg){GR_LOG_ERROR(d_logger,msg);}
751 
752  /*! \brief inline function, wrapper for NOTICE message */
753  void crit(std::string msg){GR_LOG_CRIT(d_logger,msg);}
754 
755  /*! \brief inline function, wrapper for ALERT message */
756  void alert(std::string msg){GR_LOG_ALERT(d_logger,msg);}
757 
758  /*! \brief inline function, wrapper for FATAL message */
759  void fatal(std::string msg){GR_LOG_FATAL(d_logger,msg);}
760 
761  /*! \brief inline function, wrapper for EMERG message */
762  void emerg(std::string msg){GR_LOG_EMERG(d_logger,msg);}
763 
764  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
765  void errorIF(bool cond,std::string msg){GR_LOG_ERRORIF(d_logger,cond,msg);}
766 
767  /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
768  void log_assert(bool cond,std::string msg){GR_LOG_ASSERT(d_logger,cond,msg);}
769 
770  /*! \brief inline function, Method to add appender to logger by
771  name (define appender in conf file) */
772  void add_appender(std::string appender) {
773  GR_LOG_ADD_APPENDER(d_logger, appender);
774  }
775 
776  /*! \brief inline function, Method to set an appender to logger by
777  name (define appender in conf file) */
778  void set_appender(std::string appender) {
779  GR_LOG_SET_APPENDER(d_logger, appender);
780  }
781 
782  /*! \brief inline function, Method to add console appender to logger */
783  void add_console_appender(std::string target,std::string pattern) {
784  GR_LOG_ADD_CONSOLE_APPENDER(d_logger, target, pattern);
785  }
786 
787  /*! \brief inline function, Method to set a console appender to logger */
788  void set_console_appender(std::string target,std::string pattern) {
789  GR_LOG_SET_CONSOLE_APPENDER(d_logger, target, pattern);
790  }
791 
792  /*! \brief inline function, Method to add file appender to logger */
793  void add_file_appender(std::string filename, bool append, std::string pattern) {
794  GR_LOG_ADD_FILE_APPENDER(d_logger, filename, append, pattern);
795  }
796 
797  /*! \brief inline function, Method to set a file appender to logger */
798  void set_file_appender(std::string filename, bool append, std::string pattern) {
799  GR_LOG_SET_FILE_APPENDER(d_logger, filename, append, pattern);
800  }
801 
802  /*! \brief inline function, Method to add rolling file appender to logger */
803  void add_rollingfile_appender(std::string filename, size_t filesize,
804  int bkup_index, bool append, mode_t mode,
805  std::string pattern) {
806  GR_LOG_ADD_ROLLINGFILE_APPENDER(d_logger,filename,filesize,
807  bkup_index,append,mode,pattern);
808  }
809  };
810 
811 } /* namespace gr */
812 
813 /**************** Start Configuration Class and Methods for Python ************/
814 /*!
815  * \brief Function to call configuration macro from python.
816  * Note: Configuration is only updated if filename or watch_period has changed.
817  * \param config_filename Name of configuration file
818  * \param watch_period Seconds to wait between checking for changes in conf file.
819  * Watch_period defaults to 0 in which case the file is not watched for changes
820  */
821 GR_RUNTIME_API void gr_logger_config(const std::string config_filename,
822  unsigned int watch_period = 0);
823 
824 /*!
825  * \brief Function to return logger names to python
826  * \return Vector of name strings
827  *
828  */
829 GR_RUNTIME_API std::vector<std::string> gr_logger_get_logger_names(void);
830 
831 /*!
832  * \brief Function to reset logger configuration from python
833  *
834  */
836 
837 #endif /* INCLUDED_GR_LOGGER_H */
#define GR_LOG_SET_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:88
std::string logger_ptr
Definition: logger.h:65
void add_rollingfile_appender(std::string filename, size_t filesize, int bkup_index, bool append, mode_t mode, std::string pattern)
inline function, Method to add rolling file appender to logger
Definition: logger.h:803
void set_level(std::string level)
inline function, wrapper to set the logger level
Definition: logger.h:732
#define GR_LOG_NOTICE(logger, msg)
Definition: logger.h:106
#define GR_LOG_ERROR(logger, msg)
Definition: logger.h:108
#define GR_LOG_CRIT(logger, msg)
Definition: logger.h:110
GR_RUNTIME_API void gr_logger_reset_config(void)
Function to reset logger configuration from python.
void error(std::string msg)
inline function, wrapper for LOG4CPP_ERROR for ERROR message
Definition: logger.h:750
GR_RUNTIME_API std::vector< std::string > gr_logger_get_logger_names(void)
Function to return logger names to python.
#define GR_LOG_WARN(logger, msg)
Definition: logger.h:107
#define GR_LOG_SET_LEVEL(logger, level)
Definition: logger.h:74
void set_appender(std::string appender)
inline function, Method to set an appender to logger by name (define appender in conf file) ...
Definition: logger.h:778
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern)
Definition: logger.h:90
void fatal(std::string msg)
inline function, wrapper for FATAL message
Definition: logger.h:759
#define GR_LOG_SET_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:84
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
logger(std::string logger_name)
contructor Provide name of logger to associate with this class
Definition: logger.h:723
void alert(std::string msg)
inline function, wrapper for ALERT message
Definition: logger.h:756
void warn(std::string msg)
inline function, wrapper for LOG4CPP_WARN for WARN message
Definition: logger.h:747
void add_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to add file appender to logger
Definition: logger.h:793
void get_level(std::string &level)
inline function, wrapper to get the logger level
Definition: logger.h:735
#define GR_LOG_DEBUG(logger, msg)
Definition: logger.h:104
void emerg(std::string msg)
inline function, wrapper for EMERG message
Definition: logger.h:762
#define GR_LOG_EMERG(logger, msg)
Definition: logger.h:112
boost::thread thread
Definition: thread.h:45
#define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern)
Definition: logger.h:86
void info(std::string msg)
inline function, wrapper for LOG4CPP_INFO for INFO message
Definition: logger.h:741
void add_appender(std::string appender)
inline function, Method to add appender to logger by name (define appender in conf file) ...
Definition: logger.h:772
void log_assert(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:768
#define GR_LOG_GET_LEVEL(logger, level)
Definition: logger.h:76
void add_console_appender(std::string target, std::string pattern)
inline function, Method to add console appender to logger
Definition: logger.h:783
~logger()
Destructor.
Definition: logger.h:728
void debug(std::string msg)
inline function, wrapper for LOG4CPP_DEBUG for DEBUG message
Definition: logger.h:738
void crit(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:753
#define GR_LOG_ALERT(logger, msg)
Definition: logger.h:109
#define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern)
Definition: logger.h:82
void errorIF(bool cond, std::string msg)
inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message
Definition: logger.h:765
#define GR_LOG_SET_APPENDER(logger, appender)
Definition: logger.h:80
void set_file_appender(std::string filename, bool append, std::string pattern)
inline function, Method to set a file appender to logger
Definition: logger.h:798
#define GR_LOG_ASSERT(logger, cond, msg)
Definition: logger.h:115
#define GR_LOG_ADD_APPENDER(logger, appender)
Definition: logger.h:78
GR_RUNTIME_API void gr_logger_config(const std::string config_filename, unsigned int watch_period=0)
Function to call configuration macro from python. Note: Configuration is only updated if filename or ...
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
Logger class for referencing loggers in python. Not needed in C++ (use macros) Wraps and manipulates ...
Definition: logger.h:713
void set_console_appender(std::string target, std::string pattern)
inline function, Method to set a console appender to logger
Definition: logger.h:788
void notice(std::string msg)
inline function, wrapper for NOTICE message
Definition: logger.h:744
#define GR_LOG_FATAL(logger, msg)
Definition: logger.h:111
#define GR_LOG_ASSIGN_LOGPTR(logger, name)
Definition: logger.h:69
#define GR_LOG_INFO(logger, msg)
Definition: logger.h:105
#define GR_LOG_ERRORIF(logger, cond, msg)
Definition: logger.h:113