commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 02/02: logger: adds a function to the logge


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/02: logger: adds a function to the logger facilities that allows us to update the format of the logging output.
Date: Thu, 4 Dec 2014 16:21:59 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 56f69533d1fa2114cd0a70516bdcc14243cfedfe
Author: Tom Rondeau <address@hidden>
Date:   Thu Dec 4 10:31:24 2014 -0500

    logger: adds a function to the logger facilities that allows us to update 
the format of the logging output.
---
 gnuradio-runtime/include/gnuradio/logger.h.in |  7 ++++--
 gnuradio-runtime/lib/basic_block.cc           |  2 ++
 gnuradio-runtime/lib/block.cc                 |  2 +-
 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 05367a1..941ce75 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 686c1d6..09d2eb2 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 2cc868e..9173094 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 bb1d4b4..13c8391 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 */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]