commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/07: logger: adding new configure_default


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/07: logger: adding new configure_default_logger function to make it easier to get log file info on logger setup.
Date: Thu, 14 Aug 2014 15:23:29 +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 72201e60692ee9357929d4f726c3373963c5a349
Author: Tom Rondeau <address@hidden>
Date:   Wed Aug 13 16:04:39 2014 -0400

    logger: adding new configure_default_logger function to make it easier to 
get log file info on logger setup.
---
 gnuradio-runtime/include/gnuradio/logger.h.in | 15 +++++++
 gnuradio-runtime/lib/block.cc                 | 46 +---------------------
 gnuradio-runtime/lib/logger.cc                | 56 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 45 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/logger.h.in 
b/gnuradio-runtime/include/gnuradio/logger.h.in
index 8e8cd2f..05367a1 100644
--- a/gnuradio-runtime/include/gnuradio/logger.h.in
+++ b/gnuradio-runtime/include/gnuradio/logger.h.in
@@ -834,4 +834,19 @@ GR_RUNTIME_API std::vector<std::string> 
gr_logger_get_logger_names(void);
  */
 GR_RUNTIME_API void gr_logger_reset_config(void);
 
+
+namespace gr {
+  /*!
+   * Function to use the GR prefs files to get and setup the two
+   * default loggers defined there. The loggers are unique to the
+   * class in which they are called, and we pass it the \p name to
+   * identify where the log message originates from. For a GNU Radio
+   * 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);
+} /* namespace gr */
+
+
 #endif /* INCLUDED_GR_LOGGER_H */
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index 8906d98..a15fb89 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 c11f384..961ba55 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



reply via email to

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