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