diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-08-13 16:04:39 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-08-13 16:04:39 -0400 |
commit | 72201e60692ee9357929d4f726c3373963c5a349 (patch) | |
tree | 93c434e46540352d48b480edae29f33b5c1ce509 /gnuradio-runtime/lib | |
parent | 41d0844328800cfc84c97e3961c39b5fafab11bb (diff) |
logger: adding new configure_default_logger function to make it easier to get log file info on logger setup.
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 46 | ||||
-rw-r--r-- | gnuradio-runtime/lib/logger.cc | 56 |
2 files changed, 57 insertions, 45 deletions
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index 8906d98b52..a15fb89c85 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -60,51 +60,7 @@ namespace gr { message_port_register_in(pmt::mp("system")); set_msg_handler(pmt::mp("system"), boost::bind(&block::system_handler, this, _1)); -#ifdef ENABLE_GR_LOG -#ifdef HAVE_LOG4CPP - prefs *p = prefs::singleton(); - std::string config_file = p->get_string("LOG", "log_config", ""); - std::string log_level = p->get_string("LOG", "log_level", "off"); - std::string log_file = p->get_string("LOG", "log_file", ""); - std::string debug_level = p->get_string("LOG", "debug_level", "off"); - std::string debug_file = p->get_string("LOG", "debug_file", ""); - - GR_CONFIG_LOGGER(config_file); - - GR_LOG_GETLOGGER(LOG, "gr_log." + alias()); - GR_LOG_SET_LEVEL(LOG, log_level); - if(log_file.size() > 0) { - if(log_file == "stdout") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout","gr::log :%p: %c{1} - %m%n"); - } - else if(log_file == "stderr") { - GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr","gr::log :%p: %c{1} - %m%n"); - } - else { - GR_LOG_SET_FILE_APPENDER(LOG, log_file , true,"%r :%p: %c{1} - %m%n"); - } - } - d_logger = LOG; - - GR_LOG_GETLOGGER(DLOG, "gr_log_debug." + alias()); - GR_LOG_SET_LEVEL(DLOG, debug_level); - if(debug_file.size() > 0) { - if(debug_file == "stdout") { - GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cout","gr::debug :%p: %c{1} - %m%n"); - } - else if(debug_file == "stderr") { - GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cerr", "gr::debug :%p: %c{1} - %m%n"); - } - else { - GR_LOG_SET_FILE_APPENDER(DLOG, debug_file, true, "%r :%p: %c{1} - %m%n"); - } - } - d_debug_logger = DLOG; -#endif /* HAVE_LOG4CPP */ -#else /* ENABLE_GR_LOG */ - d_logger = NULL; - d_debug_logger = NULL; -#endif /* ENABLE_GR_LOG */ + configure_default_loggers(d_logger, d_debug_logger, alias()); } block::~block() diff --git a/gnuradio-runtime/lib/logger.cc b/gnuradio-runtime/lib/logger.cc index c11f384cc6..961ba55724 100644 --- a/gnuradio-runtime/lib/logger.cc +++ b/gnuradio-runtime/lib/logger.cc @@ -31,6 +31,7 @@ #endif #include <gnuradio/logger.h> +#include <gnuradio/prefs.h> #include <stdexcept> #include <algorithm> @@ -42,6 +43,61 @@ namespace gr { bool logger_config::logger_configured(false); + + bool + configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, + const std::string name) + { +#ifdef ENABLE_GR_LOG +#ifdef HAVE_LOG4CPP + prefs *p = prefs::singleton(); + std::string config_file = p->get_string("LOG", "log_config", ""); + std::string log_level = p->get_string("LOG", "log_level", "off"); + std::string log_file = p->get_string("LOG", "log_file", ""); + std::string debug_level = p->get_string("LOG", "debug_level", "off"); + std::string debug_file = p->get_string("LOG", "debug_file", ""); + + GR_CONFIG_LOGGER(config_file); + + GR_LOG_GETLOGGER(LOG, "gr_log." + name); + GR_LOG_SET_LEVEL(LOG, log_level); + if(log_file.size() > 0) { + if(log_file == "stdout") { + GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout","gr::log :%p: %c{1} - %m%n"); + } + else if(log_file == "stderr") { + GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr","gr::log :%p: %c{1} - %m%n"); + } + else { + GR_LOG_SET_FILE_APPENDER(LOG, log_file , true,"%r :%p: %c{1} - %m%n"); + } + } + l = LOG; + + GR_LOG_GETLOGGER(DLOG, "gr_log_debug." + name); + GR_LOG_SET_LEVEL(DLOG, debug_level); + if(debug_file.size() > 0) { + if(debug_file == "stdout") { + GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cout","gr::debug :%p: %c{1} - %m%n"); + } + else if(debug_file == "stderr") { + GR_LOG_SET_CONSOLE_APPENDER(DLOG, "cerr", "gr::debug :%p: %c{1} - %m%n"); + } + else { + GR_LOG_SET_FILE_APPENDER(DLOG, debug_file, true, "%r :%p: %c{1} - %m%n"); + } + } + d = DLOG; + return true; +#endif /* HAVE_LOG4CPP */ + +#else /* ENABLE_GR_LOG */ + l = NULL; + d = NULL; + return false; +#endif /* ENABLE_GR_LOG */ + } + /************************ BEGIN LOG4CPP HELPERS ***********************/ /* Logger config class. This is a singleton that controls how * log4cpp is configured If watch_period>0 a thread is started to |