diff options
-rw-r--r-- | gnuradio-runtime/include/gnuradio/logger.h.in | 7 | ||||
-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 |
4 files changed, 39 insertions, 3 deletions
diff --git a/gnuradio-runtime/include/gnuradio/logger.h.in b/gnuradio-runtime/include/gnuradio/logger.h.in index 05367a1873..941ce75af3 100644 --- a/gnuradio-runtime/include/gnuradio/logger.h.in +++ b/gnuradio-runtime/include/gnuradio/logger.h.in @@ -844,8 +844,11 @@ namespace gr { * block, we use 'alias()' for this value, and this is set up for us * automatically in gr::block. */ - GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, - const std::string name); + GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, + const std::string name); + + GR_RUNTIME_API bool update_logger_alias(const std::string &name, const std::string &alias); + } /* namespace gr */ 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 */ |