diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-12-04 10:31:24 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-12-04 10:31:24 -0500 |
commit | 56f69533d1fa2114cd0a70516bdcc14243cfedfe (patch) | |
tree | 4a11337f2826c9860196d260885a483a90bf8d86 /gnuradio-runtime/lib | |
parent | 8236ec001ecacc8580325209bb79fee622939926 (diff) |
logger: adds a function to the logger facilities that allows us to update the format of the logging output.
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r-- | gnuradio-runtime/lib/basic_block.cc | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/logger.cc | 31 |
3 files changed, 34 insertions, 1 deletions
diff --git a/gnuradio-runtime/lib/basic_block.cc b/gnuradio-runtime/lib/basic_block.cc index 686c1d6e65..09d2eb2b3a 100644 --- a/gnuradio-runtime/lib/basic_block.cc +++ b/gnuradio-runtime/lib/basic_block.cc @@ -26,6 +26,7 @@ #include <gnuradio/basic_block.h> #include <gnuradio/block_registry.h> +#include <gnuradio/logger.h> #include <stdexcept> #include <sstream> #include <iostream> @@ -82,6 +83,7 @@ namespace gr { // set the block's alias d_symbol_alias = name; + update_logger_alias(symbol_name(), d_symbol_alias); } // ** Message passing interface ** diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index 2cc868e844..9173094e53 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -60,7 +60,7 @@ namespace gr { message_port_register_in(pmt::mp("system")); set_msg_handler(pmt::mp("system"), boost::bind(&block::system_handler, this, _1)); - configure_default_loggers(d_logger, d_debug_logger, alias()); + configure_default_loggers(d_logger, d_debug_logger, symbol_name()); } block::~block() diff --git a/gnuradio-runtime/lib/logger.cc b/gnuradio-runtime/lib/logger.cc index bb1d4b4c33..13c8391c8e 100644 --- a/gnuradio-runtime/lib/logger.cc +++ b/gnuradio-runtime/lib/logger.cc @@ -417,4 +417,35 @@ namespace gr { return false; } + bool + update_logger_alias(const std::string &name, const std::string &alias) + { +#ifdef ENABLE_GR_LOG +#ifdef HAVE_LOG4CPP + prefs *p = prefs::singleton(); + std::string log_file = p->get_string("LOG", "log_file", ""); + std::string debug_file = p->get_string("LOG", "debug_file", ""); + + GR_LOG_GETLOGGER(LOG, "gr_log." + name); + if(log_file.size() > 0) { + if(log_file == "stdout") { + boost::format str("gr::log :%%p: %1% - %%m%%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "cout", boost::str(str % alias)); + } + else if(log_file == "stderr") { + boost::format str("gr::log :%%p: %1% - %%m%%n"); + GR_LOG_SET_CONSOLE_APPENDER(LOG, "cerr", boost::str(str % alias)); + } + else { + boost::format str("%%r :%%p: %1% - %%m%%n"); + GR_LOG_SET_FILE_APPENDER(LOG, log_file, true, boost::str(str % alias)); + } + } + return true; +#endif /* HAVE_LOG4CPP */ +#endif /* ENABLE_GR_LOG */ + + return false; + } + } /* namespace gr */ |