summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/runtime/gr_block.cc
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2013-03-01 13:19:11 -0500
committerTom Rondeau <trondeau@vt.edu>2013-03-03 17:23:38 -0500
commit4fd16922d4e7ae2e5fd9dd048a873cbef409a7ff (patch)
treeea35645ece07cf4ede44f47ad10e7b8a35213634 /gnuradio-core/src/lib/runtime/gr_block.cc
parentce211603ff8821b50f7c9ebc3931498c6f2bd374 (diff)
log: adding default loggers to all gr_blocks to make using them simpler.
log: improving logger configuration and default behavior. log: changed name from gr_log to gr_logger (felt it could be confuse with the math function log). docs: moved logging information out to its own page.
Diffstat (limited to 'gnuradio-core/src/lib/runtime/gr_block.cc')
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index 54d2676203..0dc9fe670d 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -29,6 +29,7 @@
#include <stdexcept>
#include <iostream>
#include <gr_block_registry.h>
+#include <gr_prefs.h>
gr_block::gr_block (const std::string &name,
gr_io_signature_sptr input_signature,
@@ -49,6 +50,52 @@ gr_block::gr_block (const std::string &name,
d_min_output_buffer(std::max(output_signature->max_streams(),1), -1)
{
global_block_registry.register_primitive(alias(), this);
+
+#ifdef ENABLE_GR_LOG
+#ifdef HAVE_LOG4CXX
+ gr_prefs *p = gr_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_ADD_CONSOLE_APPENDER(LOG, "gr::log :%p: %c{1} - %m%n", "System.out");
+ }
+ else if(log_file == "stderr") {
+ GR_LOG_ADD_CONSOLE_APPENDER(LOG, "gr::log :%p: %c{1} - %m%n", "System.err");
+ }
+ else {
+ GR_LOG_ADD_FILE_APPENDER(LOG, "%r :%p: %c{1} - %m%n", log_file, "");
+ }
+ }
+ 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_ADD_CONSOLE_APPENDER(DLOG, "gr::log :%p: %c{1} - %m%n", "System.out");
+ }
+ else if(debug_file == "stderr") {
+ GR_LOG_ADD_CONSOLE_APPENDER(DLOG, "gr::log :%p: %c{1} - %m%n", "System.err");
+ }
+ else {
+ GR_LOG_ADD_FILE_APPENDER(DLOG, "%r :%p: %c{1} - %m%n", debug_file, "");
+ }
+ }
+ d_debug_logger = DLOG;
+#endif /* HAVE_LOG4CXX */
+#else /* ENABLE_GR_LOG */
+ d_logger = NULL;
+ d_debug_logger = NULL;
+#endif /* ENABLE_GR_LOG */
}
gr_block::~gr_block ()