summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/doxygen/other/logger.dox31
-rw-r--r--gnuradio-core/CMakeLists.txt2
-rw-r--r--gnuradio-core/gr_log_default.conf40
-rw-r--r--gnuradio-core/gr_log_default.xml64
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.cc173
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.h411
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.i84
7 files changed, 469 insertions, 336 deletions
diff --git a/docs/doxygen/other/logger.dox b/docs/doxygen/other/logger.dox
index 22458051db..f5228cfc55 100644
--- a/docs/doxygen/other/logger.dox
+++ b/docs/doxygen/other/logger.dox
@@ -24,8 +24,9 @@ different levels. These levels are:
The order here determines the level of output. These levels are
hierarchical in that specifying any level also includes any level
-above it. For example, when using the WARN level, all WARN and
-higher messages are logged while DEBUG and INFO are ignored.
+above it. For example, when using the INFO level, all INFO and
+higher messages are logged and DEBUG is ignored. A level NOTSET is provided
+to disable a logger.
\subsection configfile Logging Configuration
@@ -143,7 +144,7 @@ provided with GNU Radio can be used. After installation, the default
configuration script is located at:
<pre>
- $prefix/etc/gnuradio/gr_log_default.xml
+ $prefix/etc/gnuradio/gr_log_default.conf
</pre>
For the following examples, we will assume that our local
@@ -151,12 +152,12 @@ For the following examples, we will assume that our local
\code
[LOG]
-log_config = /opt/gr/etc/gnuadio/gr_log_default.xml
+log_config = /opt/gr/etc/gnuadio/gr_log_default.conf
log_level = debug
debug_level = Off
\endcode
-Inside of the XML default configuration file, we define the parameters
+Inside of the default configuration file, we define the parameters
for the two logger's, the standard logger the separate debug logger.
If the levels of the two loggers are specified in our configuration
@@ -202,4 +203,24 @@ This creates a pointer called LOG (which is instantiated as a
log4cpp:LoggerPtr in the macro) that we can now use locally as the
input to our logging macros like 'GR_LOG_INFO(LOG, "message")'.
+\section logPy Logging from Python
+
+The logging capability has been brought out python via swig. The configuration
+of the logger can be manipulated via the following calls:
+\code
+ from gnuradio import gr
+ gr.logger_config(filename,watch_period) # Configures the logger with conf file filename
+ names = gr.logger_get_logger_names() # Returns the names of all loggers
+ gr.logger_reset_config() # Resets logger config by removing all appenders
+\endcode
+
+Once the logger is configured you can manipulate a logger via a wrapper class gr.logger().
+You can isntantiate this by the following. (Reference gr_logger.h for list of methods)
+\code
+ from gnuradio import gr
+ log=gr.logger("nameOfLogger")
+ log.debug("Log a debug message")
+ log.set_level("INFO");
+
+\endcode
*/
diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt
index 3dcffa2184..6a88b63cc7 100644
--- a/gnuradio-core/CMakeLists.txt
+++ b/gnuradio-core/CMakeLists.txt
@@ -148,7 +148,7 @@ install(
if(ENABLE_GR_LOG AND HAVE_LOG4CPP)
install(FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/gr_log_default.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_log_default.conf
DESTINATION ${GR_CONF_DIR}/gnuradio
COMPONENT "core_runtime"
)
diff --git a/gnuradio-core/gr_log_default.conf b/gnuradio-core/gr_log_default.conf
new file mode 100644
index 0000000000..79c2d91e94
--- /dev/null
+++ b/gnuradio-core/gr_log_default.conf
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006,2010,2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+log4j.rootCategory=EMERG,A1
+log4j.category.gr_log=DEBUG,A2
+log4j.category.gr_log_debug=NOTSET,A3
+
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.target=System.out
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=Root :%p: %c{1} - %m%n
+
+log4j.appender.A2=org.apache.log4j.ConsoleAppender
+log4j.appender.A2.target=System.out
+log4j.appender.A2.layout=org.apache.log4j.PatternLayout
+log4j.appender.A2.layout.ConversionPattern=gr::log :%p: %c{1} - %m%n
+
+log4j.appender.A3=org.apache.log4j.ConsoleAppender
+log4j.appender.A3.target=System.out
+log4j.appender.A3.layout=org.apache.log4j.PatternLayout
+log4j.appender.A3.layout.ConversionPattern=gr::debug :%p: %c{1} - %m%n
+
diff --git a/gnuradio-core/gr_log_default.xml b/gnuradio-core/gr_log_default.xml
deleted file mode 100644
index 13b854c7e8..0000000000
--- a/gnuradio-core/gr_log_default.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- * Copyright 2006,2010,2011 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
--->
-
- <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
-
- <appender name="RootConsoleAppender" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out"/>
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="Root :%p: %c{1} - %m%n"/>
- </layout>
- </appender>
-
- <!--Add appender to root to log ALL msgs in one place-->
- <root>
- <priority value="all" />
- </root>
-
- <appender name="errLogRootConsoleAppender" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out"/>
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="gr::log :%p: %c{1} - %m%n"/>
- </layout>
- </appender>
-
- <!-- Specify the level for some specific loggers-->
- <category name="gr_log" >
- <priority value ="all" />
- <appender-ref ref="errLogRootConsoleAppender"/>
- </category>
-
- <appender name="errConsoleAppender" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out"/>
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="gr::debug :%p: %c{1} - %m%n"/>
- </layout>
- </appender>
-
- <category name="gr_log_debug" >
- <priority value ="DEBUG" />
- <appender-ref ref="errConsoleAppender"/>
- </category>
-
- </log4j:configuration>
-
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.cc b/gnuradio-core/src/lib/runtime/gr_logger.cc
index 530c66f964..7e0116d036 100644
--- a/gnuradio-core/src/lib/runtime/gr_logger.cc
+++ b/gnuradio-core/src/lib/runtime/gr_logger.cc
@@ -26,10 +26,6 @@
* The gr_log module wraps the log4cpp library for logging in gnuradio.
*******************************************************************************/
-//#ifdef HAVE_CONFIG_H
-//#include "config.h"
-//#endif
-
#include <gr_logger.h>
#include <stdexcept>
#include <algorithm>
@@ -37,33 +33,118 @@
#ifdef ENABLE_GR_LOG
#ifdef HAVE_LOG4CPP
-bool gr_logger_configured(false);
+/**************************** 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 watch teh config file for changes.
+ */
-void
-logger_load_config(const std::string &config_filename)
-{
- if(!gr_logger_configured){
- gr_logger_configured = true;
- if(config_filename.size() != 0) {
- try
- {
- log4cpp::PropertyConfigurator::configure(config_filename);
- }
- catch( log4cpp::ConfigureFailure &e )
- {
- std::cout << "Logger config failed :" << e.what() << std::endl;
- }
- };
+// Getters of logger_config
+logger_config&
+logger_config::get_instance(void){
+ static logger_config instance;
+ return instance;
+};
+
+std::string
+logger_config::get_filename(){
+ logger_config& in=get_instance();
+ return in.filename;
+};
+
+unsigned int
+logger_config::get_watch_period(){
+ logger_config& in=get_instance();
+ return in.watch_period;
+};
+
+// Method to watch config file for changes
+void logger_config::watch_file(std::string filename,unsigned int watch_period){
+ std::time_t last_write(boost::filesystem::last_write_time(filename));
+ std::time_t current_time(0);
+ while(true){
+ try{
+ current_time = boost::filesystem::last_write_time(filename);
+ if(current_time>last_write){
+ std::cout<<"GNURadio Reloading logger configuration:"<<filename<<std::endl;
+ last_write = current_time;
+// Should we wipe out all old configuration or just add the new? Just adding...
+// logger_reset_config();
+ logger_load_config(filename);
+ };
+ boost::this_thread::sleep(boost::posix_time::time_duration(0,0,watch_period,0));
+ }
+ catch(const boost::thread_interrupted&){
+ std::cout<<"GNURadio leaving logger config file watch."<<std::endl;
+ break;
+ };
+ };
+};
+
+// Method to load the confifuration. It only loads if the filename or watch has changed
+void logger_config::load_config(std::string filename,unsigned int watch_period){
+ logger_config& instance = get_instance();
+// Only reconfigure if filename or watch has changed
+ if(instance.filename!=filename || watch_period!=instance.watch_period){
+ instance.filename = filename;
+ instance.watch_period = watch_period;
+// Stop any file watching thread
+ if(instance.watch_thread!=NULL) stop_watch();
+// Load configuration
+ std::cout<<"GNURadio Loading logger configuration:"<<instance.filename<<std::endl;
+ logger_load_config(instance.filename);
+// Start watch if required
+ if(instance.watch_period>0){
+ instance.watch_thread = new boost::thread(watch_file,instance.filename,instance.watch_period);
+ }
};
+};
+
+// Method to stop the watcher thread
+void logger_config::stop_watch(){
+ logger_config& instance = get_instance();
+ if(instance.watch_thread){
+ instance.watch_thread->interrupt();
+ instance.watch_thread->join();
+ delete(instance.watch_thread);
+ instance.watch_thread=NULL;
+ };
+};
+
+// Method to reset logger configuration
+void
+logger_config::reset_config(void){
+ logger_config& instance = get_instance();
+ stop_watch();
+ std::vector<log4cpp::Category*> *loggers = log4cpp::Category::getCurrentCategories();
+ std::vector<log4cpp::Category*>::iterator logger = loggers->begin();
+// We can't destroy categories but we can neuter them by removing all appenders.
+ for (;logger!=loggers->end();logger++){
+ (*logger)->removeAllAppenders();
+ };
+ instance.filename=std::string("");
+ instance.watch_period=0;
}
+/***************** Functions to call log4cpp methods *************************/
+
+gr_logger_ptr
+logger_get_logger(std::string name)
+{
+ if(log4cpp::Category::exists(name)){
+ gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
+ return logger;
+ }
+ else
+ {
+ gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
+ logger->setPriority(log4cpp::Priority::NOTSET);
+ return logger;
+ };
+};
+
void
-logger_load_config_and_watch(const std::string &config_filename,
- unsigned int watch_period)
+logger_load_config(const std::string &config_filename)
{
-// NOTE:: NEEDS CODE TO WATCH FILE HERE
- if(!gr_logger_configured){
- gr_logger_configured = true;
if(config_filename.size() != 0) {
try
{
@@ -74,17 +155,6 @@ logger_load_config_and_watch(const std::string &config_filename,
std::cout << "Logger config failed :" << e.what() << std::endl;
}
};
- };
-}
-
-void
-logger_reset_config(void){
- std::vector<log4cpp::Category*> *loggers = log4cpp::Category::getCurrentCategories();
- std::vector<log4cpp::Category*>::iterator logger = loggers->begin();
-// We can't destroy categories but we can neuter them by removing all appenders.
- for (;logger!=loggers->end();logger++){
- (*logger)->removeAllAppenders();
- };
}
void
@@ -95,7 +165,7 @@ logger_set_level(gr_logger_ptr logger, const std::string &level)
if(nocase == "off" || nocase == "notset")
logger_set_level(logger, log4cpp::Priority::NOTSET);
- else if(nocase == "debug")
+ else if(nocase == "all" || nocase == "debug")
logger_set_level(logger, log4cpp::Priority::DEBUG);
else if(nocase == "info")
logger_set_level(logger, log4cpp::Priority::INFO);
@@ -111,7 +181,7 @@ logger_set_level(gr_logger_ptr logger, const std::string &level)
logger_set_level(logger, log4cpp::Priority::ALERT);
else if(nocase=="fatal")
logger_set_level(logger, log4cpp::Priority::FATAL);
- else if(nocase == "all" || nocase == "emerg")
+ else if(nocase == "emerg")
logger_set_level(logger, log4cpp::Priority::EMERG);
else
throw std::runtime_error("logger_set_level: Bad level type.\n");
@@ -151,7 +221,7 @@ logger_add_console_appender(gr_logger_ptr logger,std::string target,std::string
log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
log4cpp::Appender* app;
- if(target=="cout")
+ if(target=="stdout")
app = new log4cpp::OstreamAppender("ConsoleAppender::",&std::cout);
else
app = new log4cpp::OstreamAppender("ConsoleAppender::",&std::cerr);
@@ -188,17 +258,34 @@ logger_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,
logger->setAppender(app);
}
-void
-logger_get_logger_names(std::vector<std::string>& names){
+std::vector<std::string>
+logger_get_logger_names(void){
+ std::vector<std::string> names;
std::vector<log4cpp::Category*> *loggers = log4cpp::Category::getCurrentCategories();
std::vector<log4cpp::Category*>::iterator logger = loggers->begin();
- names.clear();
for (;logger!=loggers->end();logger++){
names.push_back((*logger)->getName());
};
-
+ return names;
+
}
#endif /* HAVE_LOG4CPP */
+
+/****** Start Methods to provide Python the capabilities of the macros ********/
+void gr_logger_config(const std::string config_filename, unsigned int watch_period){
+ GR_CONFIG_AND_WATCH_LOGGER(config_filename,watch_period);
+};
+std::vector<std::string> gr_logger_get_logger_names(void){
+ std::vector<std::string> names;
+ GR_GET_LOGGER_NAMES(names);
+ return names;
+};
+void gr_logger_reset_config(void){
+ GR_RESET_CONFIGURATION();
+};
+
+// Remaining capability provided by gr_logger class in gr_logger.h
+
#endif /* ENABLE_GR_LOGGER */
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.h b/gnuradio-core/src/lib/runtime/gr_logger.h
index 2ccd498822..db6df722ec 100644
--- a/gnuradio-core/src/lib/runtime/gr_logger.h
+++ b/gnuradio-core/src/lib/runtime/gr_logger.h
@@ -38,19 +38,14 @@
#ifndef ENABLE_GR_LOG
#include "config.h"
-//#define GR_LOG_CONFIG_H
#endif
#include <gr_core_api.h>
#include <assert.h>
#include <iostream>
-
-//#ifndef ENABLE_GR_LOG
-//#define ENABLE_GR_LOG 1
-//#endif
-//#ifndef HAVE_LOG4CPP
-//#define HAVE_LOG4CPP 2
-//#endif
+#include <time.h>
+#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
#ifdef ENABLE_GR_LOG
@@ -86,8 +81,8 @@ typedef std::string gr_logger_ptr;
#define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
#define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
#define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
-#define GR_ERRORIF(name, cond, msg) if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl
-#define GR_ASSERT(name, cond, msg) if(!(cond)) std::cerr<<"ERROR: "<<msg<<std::endl; assert(cond)
+#define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
+#define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
#define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
#define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
#define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
@@ -97,8 +92,10 @@ typedef std::string gr_logger_ptr;
#define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
#define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
#define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
-#define GR_LOG_ERRORIF(logger, cond, msg) if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl
-#define GR_LOG_ASSERT(logger, cond, msg) std::cerr<<"ERROR: "<<msg<<std::endl; assert(cond)
+#define GR_LOG_ERRORIF(logger, cond, msg) {\
+ if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
+#define GR_LOG_ASSERT(logger, cond, msg) {\
+ if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
#else /* HAVE_LOG4CPP */
// Second configuration...logging to log4cpp
@@ -133,104 +130,104 @@ typedef log4cpp::Category* gr_logger_ptr;
gr_logger_ptr logger;
#define GR_LOG_ASSIGN_LOGPTR(logger,name) \
- logger = gr_logger::getLogger(name);
+ logger = logger_get_logger(name);
#define GR_CONFIG_LOGGER(config) \
- logger_load_config(config)
+ logger_config::load_config(config)
#define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
- logger_load_config_and_watch(config,period)
+ logger_config::load_config(config,period)
#define GR_LOG_GETLOGGER(logger, name) \
- gr_logger_ptr logger = gr_logger::getLogger(name);
+ gr_logger_ptr logger = logger_get_logger(name);
#define GR_SET_LEVEL(name, level){ \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
logger_set_level(logger,level);}
#define GR_LOG_SET_LEVEL(logger, level) \
logger_set_level(logger, level);
#define GR_GET_LEVEL(name, level){ \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
logger_get_level(logger,level);}
#define GR_LOG_GET_LEVEL(logger, level) \
logger_get_level(logger,level);
#define GR_ADD_CONSOLE_APPENDER(name,target,pattern){\
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
logger_add_console_appender(logger,target,pattern);}
#define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern){\
logger_add_console_appender(logger,target,pattern);}
#define GR_ADD_FILE_APPENDER(name,filename,append,pattern){\
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
logger_add_file_appender(logger,filename,append,pattern);}
#define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern){\
logger_add_file_appender(logger,filename,append,pattern);}
#define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern){\
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern){\
logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
#define GR_GET_LOGGER_NAMES(names){ \
- logger_get_logger_names(names);}
+ names = logger_get_logger_names();}
#define GR_RESET_CONFIGURATION(){ \
- logger_reset_config();}
+ logger_config::reset_config();}
/* Logger name referenced macros */
#define GR_DEBUG(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
#define GR_INFO(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
#define GR_NOTICE(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger << log4cpp::Priority::NOTICE << msg;}
#define GR_WARN(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
#define GR_ERROR(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
#define GR_CRIT(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
#define GR_ALERT(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
#define GR_FATAL(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
#define GR_EMERG(name, msg) { \
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
#define GR_ERRORIF(name, cond, msg) { \
if((cond)){\
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;};\
};
#define GR_ASSERT(name, cond, msg) { \
-if((!cond)){\
- gr_logger_ptr logger = gr_logger::getLogger(name);\
+if(!(cond)){\
+ gr_logger_ptr logger = logger_get_logger(name);\
*logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;};\
assert(0);\
};
@@ -264,18 +261,75 @@ if((!cond)){\
*logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
#define GR_LOG_ERRORIF(logger,cond, msg) { \
-if((!cond)){\
+if((cond)){\
*logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;};\
- assert(0);\
};
#define GR_LOG_ASSERT(logger, cond, msg) { \
-if((!cond)){\
- *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;};\
- assert(0);\
+if(!(cond)){\
+ *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;\
+ assert(0);};\
};
/*!
+ * \brief Class to control configuration of logger.
+ * This is a singleton that cna launch a thread to wathc a config file for changes
+ * \ingroup logging
+ */
+class logger_config {
+private:
+ /*! \brief filename of logger config file */
+ std::string filename;
+ /*! \brief Period (seconds) over which watcher thread checks config file for changes */
+ unsigned int watch_period;
+ /*! \brief Pointer to watch thread for config file changes */
+ boost::thread *watch_thread;
+
+ /*! \brief Watcher thread method
+ * /param filename Name of configuration file
+ * /param watch_period Seconds between checks for changes in config file
+ */
+ static void watch_file(std::string filename,unsigned int watch_period);
+
+ logger_config(){}; //!< Constructor
+ logger_config(logger_config const&); //!<Copy constructor
+ void operator=(logger_config const&); //!<Assignment Operator
+
+ /*! \brief destrcutor stops watch thread before exits */
+ ~logger_config(){
+ stop_watch();
+ };
+
+ /*! \brief Instance getter for singleton. Only used by class. */
+ static logger_config& get_instance(void);
+
+public:
+ /*! \brief Getter for config filename */
+ static std::string get_filename();
+ /*! \brief Getter for watch period */
+ static unsigned int get_watch_period();
+ /*! \brief Method to load configuration
+ * /param filename Name of configuration file
+ * /param watch_period Seconds between checks for changes in config file
+ */
+ static void load_config(std::string filename,unsigned int watch_period=0);
+ /*! \brief Method to stop watcher thread */
+ static void stop_watch();
+ /*! \brief method to reset logger configuration */
+ static void reset_config(void);
+};
+
+/*!
+ * \brief Retrieve a pointer to a logger by name
+ *
+ * Retrives a logger pointer
+ * \p name.
+ *
+ * \param name Name of the logger for which a pointer is requested
+ */
+GR_CORE_API gr_logger_ptr logger_get_logger(std::string name);
+
+/*!
* \brief Load logger's configuration file.
*
* Initialize the GNU Radio logger by loading the configuration file
@@ -286,10 +340,11 @@ if((!cond)){\
*/
GR_CORE_API void logger_load_config(const std::string &config_filename="");
-
-GR_CORE_API void logger_load_config_and_watch(const std::string &config_filename,
- unsigned int watch_period);
-
+/*!
+ * \brief Reset logger's configuration file.
+ *
+ * Remove all appenders from loggers
+ */
GR_CORE_API void logger_reset_config(void);
/*!
@@ -334,7 +389,7 @@ GR_CORE_API void logger_set_level(gr_logger_ptr logger, const std::string &level
* \param logger the logger to set the level of.
* \param level new logger level of type Log4cpp::Priority
*/
-void logger_set_level(gr_logger_ptr logger, log4cpp::Priority::Value level);
+GR_CORE_API void logger_set_level(gr_logger_ptr logger, log4cpp::Priority::Value level);
/*!
@@ -381,140 +436,57 @@ GR_CORE_API void logger_get_level(gr_logger_ptr logger, std::string &level);
*/
GR_CORE_API void logger_get_level(gr_logger_ptr logger, log4cpp::Priority::Value &level);
+/*!
+ * \brief Add console appender to a given logger
+ *
+ * Add console appender to a given logger
+ *
+ * \param logger Logger to which appender will be added
+ * \param target Std target to write 'cout' or 'cerr' (default is cout)
+ * \param pattern Formating pattern for log messages
+ */
GR_CORE_API void logger_add_console_appender(gr_logger_ptr logger,std::string target,std::string pattern);
+/*!
+ * \brief Add file appender to a given logger
+ *
+ * Add file appender to a given logger
+ *
+ * \param logger Logger to which appender will be added
+ * \param filename File to which log will be written
+ * \param append Overwrite or append to log file
+ * \param pattern Formating pattern for log messages
+ */
GR_CORE_API void logger_add_file_appender(gr_logger_ptr logger,std::string filename,bool append,std::string pattern);
+/*!
+ * \brief Add rolling file appender to a given logger
+ *
+ * Add rolling file appender to a given logger
+ *
+ * \param logger Logger to which appender will be added
+ * \param filename File to which log will be written
+ * \param filesize Sizez of files to write
+ * \param bkup_index Number of files to write
+ * \param append Overwrite or append to log file
+ * \param mode Permissions to set on log file
+ * \param pattern Formating pattern for log messages
+ */
GR_CORE_API void logger_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,
size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern);
-GR_CORE_API void logger_get_logger_names(std::vector<std::string>& names);
-
/*!
- * \brief instantiate (configure) logger.
- * \ingroup logging
+ * \brief Add rolling file appender to a given logger
+ *
+ * Add rolling file appender to a given logger
*
+ * \return vector of string names of loggers
*/
-class gr_logger
-{
- public:
- /*!
- * \brief contructor take log configuration file and configures loggers.
- */
- gr_logger(std::string config_filename)
- {
- // Load configuration file
- logger_load_config(config_filename);
- };
-
- /*!
- * \brief contructor take log configuration file and watchtime and configures
- */
- gr_logger(std::string config_filename, int watchPeriodSec)
- {
- // Load configuration file
- logger_load_config_and_watch(config_filename,watchPeriodSec);
-
- };
-
- static gr_logger_ptr getLogger(std::string name)
- {
- if(log4cpp::Category::exists(name)){
- gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
- return logger;
- }
- else
- {
- gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
- logger->setPriority(log4cpp::Priority::NOTSET);
- return logger;
- };
- };
-
- // Wrappers for logging macros
- /*! \brief inline function, wrapper to set the logger level */
- void set_level(std::string name,std::string level){GR_SET_LEVEL(name,level);}
-
- /*! \brief inline function, wrapper to get the logger level */
- void get_level(std::string name,std::string &level){GR_GET_LEVEL(name,level);}
-
- /*! \brief inline function, wrapper for DEBUG message */
- void debug(std::string name,std::string msg){GR_DEBUG(name,msg);};
-
- /*! \brief inline function, wrapper for INFO message */
- void info(std::string name,std::string msg){GR_INFO(name,msg);};
-
- /*! \brief inline function, wrapper for NOTICE message */
- void notice(std::string name,std::string msg){GR_NOTICE(name,msg);};
-
- /*! \brief inline function, wrapper for WARN message */
- void warn(std::string name,std::string msg){GR_WARN(name,msg);};
-
- /*! \brief inline function, wrapper for ERROR message */
- void error(std::string name,std::string msg){GR_ERROR(name,msg);};
-
- /*! \brief inline function, wrapper for CRIT message */
- void crit(std::string name,std::string msg){GR_CRIT(name,msg);};
-
- /*! \brief inline function, wrapper for ALERT message */
- void alert(std::string name,std::string msg){GR_ALERT(name,msg);};
-
- /*! \brief inline function, wrapper for FATAL message */
- void fatal(std::string name,std::string msg){GR_FATAL(name,msg);};
-
- /*! \brief inline function, wrapper for EMERG message */
- void emerg(std::string name,std::string msg){GR_EMERG(name,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
- void errorIF(std::string name,bool cond,std::string msg){GR_ERRORIF(name,cond,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
- void gr_assert(std::string name,bool cond,std::string msg){GR_ASSERT(name,cond,msg);};
-
- // Wrappers for Logger Pointer referenced functions
- /*! \brief inline function, wrapper to set the logger level */
- void set_log_level(gr_logger_ptr logger,std::string level){GR_LOG_SET_LEVEL(logger,level);}
-
- /*! \brief inline function, wrapper to get the logger level */
- void get_log_level(gr_logger_ptr logger,std::string &level){GR_LOG_GET_LEVEL(logger,level);}
-
- /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
- void log_debug(gr_logger_ptr logger,std::string msg){GR_LOG_DEBUG(logger,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
- void log_info(gr_logger_ptr logger,std::string msg){GR_LOG_INFO(logger,msg);};
-
- /*! \brief inline function, wrapper for NOTICE message */
- void log_notice(gr_logger_ptr logger,std::string msg){GR_LOG_NOTICE(logger,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
- void log_warn(gr_logger_ptr logger,std::string msg){GR_LOG_WARN(logger,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
- void log_error(gr_logger_ptr logger,std::string msg){GR_LOG_ERROR(logger,msg);};
-
- /*! \brief inline function, wrapper for NOTICE message */
- void log_crit(gr_logger_ptr logger,std::string msg){GR_LOG_CRIT(logger,msg);};
-
- /*! \brief inline function, wrapper for ALERT message */
- void log_alert(gr_logger_ptr logger,std::string msg){GR_LOG_ALERT(logger,msg);};
-
- /*! \brief inline function, wrapper for FATAL message */
- void log_fatal(gr_logger_ptr logger,std::string msg){GR_LOG_FATAL(logger,msg);};
-
- /*! \brief inline function, wrapper for EMERG message */
- void log_emerg(gr_logger_ptr logger,std::string msg){GR_LOG_EMERG(logger,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
- void log_errorIF(gr_logger_ptr logger,bool cond,std::string msg){GR_LOG_ERRORIF(logger,cond,msg);};
-
- /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
- void log_assert(gr_logger_ptr logger,bool cond,std::string msg){GR_LOG_ASSERT(logger,cond,msg);};
-};
-
+GR_CORE_API std::vector<std::string> logger_get_logger_names(void);
#endif /* HAVE_LOG4CPP */
+
// If Logger disable do nothing
#else /* ENABLE_GR_LOG */
@@ -561,4 +533,111 @@ typedef void* gr_logger_ptr;
#define GR_LOG_ASSERT(logger, cond, msg)
#endif /* ENABLE_GR_LOG */
+
+// Even if logger is disabled we'll need for methods below to exist in python.
+// The macros these call will be disabled if ENABLE_GR_LOG is undefined
+
+/********************* Start Classes and Methods for Python ******************/
+/*!
+ * \brief Logger class for referencing loggers in python. Not needed in C++ (use macros)
+ * Wraps and manipulates loggers for python as python has no macros
+ * \ingroup logging
+ *
+ */
+class gr_logger
+{
+ private:
+ /*! \brief logger pointer to logger associated wiith this wrapper class */
+ gr_logger_ptr d_logger;
+ public:
+ /*!
+ * \brief contructor Provide name of logger to associate with this class
+ * \param logger_name Name of logger associated with class
+ */
+ gr_logger(std::string logger_name) {
+ GR_LOG_ASSIGN_LOGPTR(d_logger,logger_name);
+ };
+
+ /*! \brief Destructor */
+ ~gr_logger(){;};
+
+ // Wrappers for logging macros
+ /*! \brief inline function, wrapper to set the logger level */
+ void set_level(std::string level){GR_LOG_SET_LEVEL(d_logger,level);}
+
+ /*! \brief inline function, wrapper to get the logger level */
+ void get_level(std::string &level){GR_LOG_GET_LEVEL(d_logger,level);}
+
+ /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
+ void debug(std::string msg){GR_LOG_DEBUG(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
+ void info(std::string msg){GR_LOG_INFO(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for NOTICE message */
+ void notice(std::string msg){GR_LOG_NOTICE(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
+ void warn(std::string msg){GR_LOG_WARN(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
+ void error(std::string msg){GR_LOG_ERROR(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for NOTICE message */
+ void crit(std::string msg){GR_LOG_CRIT(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for ALERT message */
+ void alert(std::string msg){GR_LOG_ALERT(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for FATAL message */
+ void fatal(std::string msg){GR_LOG_FATAL(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for EMERG message */
+ void emerg(std::string msg){GR_LOG_EMERG(d_logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void errorIF(bool cond,std::string msg){GR_LOG_ERRORIF(d_logger,cond,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void log_assert(bool cond,std::string msg){GR_LOG_ASSERT(d_logger,cond,msg);};
+
+ /*! \brief inline function, Method to add console appender to logger */
+ void add_console_appender(std::string target,std::string pattern){
+ GR_LOG_ADD_CONSOLE_APPENDER(d_logger,target,pattern);
+ };
+
+ /*! \brief inline function, Method to add file appender to logger */
+ void add_file_appender(std::string filename,bool append,std::string pattern){
+ GR_LOG_ADD_FILE_APPENDER(d_logger,filename,append,pattern);
+ };
+
+ /*! \brief inline function, Method to add rolling file appender to logger */
+ void add_rollingfile_appender(std::string filename,size_t filesize,
+ int bkup_index,bool append,mode_t mode,std::string pattern){
+ GR_LOG_ADD_ROLLINGFILE_APPENDER(d_logger,filename,filesize,
+ bkup_index,append,mode,pattern);
+ };
+};
+
+/**************** Start Configuration Class and Methods for Python ************/
+/*!
+ * \brief Function to call configuration macro from python.
+ * Note: Configuration is only updated if filename or watch_period has changed.
+ * \param config_filename Name of configuration file
+ * \param watch_period Seconds to wait between checking for changes in conf file.
+ * Watch_period defaults to 0 in which case the file is not watched for changes
+ */
+GR_CORE_API void gr_logger_config(const std::string config_filename, unsigned int watch_period = 0);
+/*!
+ * \brief Function to return logger names to python
+ * \return Vector of name strings
+ *
+ */
+GR_CORE_API std::vector<std::string> gr_logger_get_logger_names(void);
+/*!
+ * \brief Function to reset logger configuration from python
+ *
+ */
+GR_CORE_API void gr_logger_reset_config(void);
+
#endif /* INCLUDED_GR_LOGGER_H */
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.i b/gnuradio-core/src/lib/runtime/gr_logger.i
index 70e50e02b3..b43bff5a89 100644
--- a/gnuradio-core/src/lib/runtime/gr_logger.i
+++ b/gnuradio-core/src/lib/runtime/gr_logger.i
@@ -39,71 +39,41 @@
//-----------------------------------
-#ifdef ENABLE_GR_LOG
-#ifdef HAVE_LOG4CPP
-
%{
// The .h files
#include <gr_logger.h>
-#include <log4cpp/Category.hh>
%}
-namespace log4cpp{
-class LoggerPtr {
-public:
- ~LoggerPtr();
-};
-};
-void logger_load_config(const std::string &config_filename);
-void logger_set_level(log4cpp::LoggerPtr logger, const std::string &level);
+%rename(logger) gr_logger;
+%rename(logger_config) gr_logger_config;
+%rename(logger_get_names) gr_logger_get_logger_names;
+%rename(logger_reset_config) gr_logger_reset_config;
-%rename(log) gr_logger;
+
+void gr_logger_config(const std::string config_filename,unsigned int watch_period = 0);
+std::vector<std::string> gr_logger_get_logger_names(void);
+void gr_logger_reset_config(void);
class gr_logger
{
-private:
-
-public:
- //gr_logger(std::string config_filename);
- gr_logger(std::string config_filename,int watchPeriodSec);
- void set_level(std::string name,std::string level);
- void get_level(std::string name,std::string &level);
- void add_console_appender(std::string name,std::string target,std::string pattern);
- void add_file_appender(std::string name,std::string filename,bool append,std::string patter);
- void add_rollingfile_appender(std::string name,std::string filename,size_t filesize,int bkup_indx,bool append,mode_t mode,std::string pattern);
-
- void notice(std::string name,std::string msg);
- void debug(std::string name,std::string msg);
- void info(std::string name,std::string msg);
- void warn(std::string name,std::string msg);
- void error(std::string name,std::string msg);
- void emerg(std::string name,std::string msg);
- void crit(std::string name,std::string msg);
- void errorIF(std::string name,bool cond,std::string msg);
- void gr_assert(std::string name,bool cond,std::string msg);
-
- static gr_logger_ptr getLogger(std::string name);
-
- void log_set_level(gr_logger_ptr logger,std::string level);
- void log_get_level(gr_logger_ptr logger,std::string &level);
- void log_add_console_appender(gr_logger_ptr logger,std::string target,std::string pattern);
- void log_add_file_appender(gr_logger_ptr logger,std::string filename,bool append,std::string pattern);
- void log_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern);
-
- void log_notice(gr_logger_ptr logger,std::string msg);
- void log_debug(gr_logger_ptr logger,std::string msg);
- void log_info(gr_logger_ptr logger,std::string msg);
- void log_warn(gr_logger_ptr logger,std::string msg);
- void log_error(gr_logger_ptr logger,std::string msg);
- void log_crit(gr_logger_ptr logger,std::string msg);
- void log_emerg(gr_logger_ptr logger,std::string msg);
- void log_errorIF(gr_logger_ptr logger,bool cond,std::string msg);
- void log_assert(gr_logger_ptr logger,bool cond,std::string msg);
-
- void get_logger_names(std::vector<std::string>& names);
- void reset_configuration();
-
+ public:
+ gr_logger(std::string logger_name);
+ void set_level(std::string level){GR_LOG_SET_LEVEL(d_logger,level);}
+ void get_level(std::string &level){GR_LOG_GET_LEVEL(d_logger,level);}
+ void debug(std::string msg){GR_LOG_DEBUG(d_logger,msg);};
+ void info(std::string msg){GR_LOG_INFO(d_logger,msg);};
+ void notice(std::string msg){GR_LOG_NOTICE(d_logger,msg);};
+ void warn(std::string msg){GR_LOG_WARN(d_logger,msg);};
+ void error(std::string msg){GR_LOG_ERROR(d_logger,msg);};
+ void crit(std::string msg){GR_LOG_CRIT(d_logger,msg);};
+ void alert(std::string msg){GR_LOG_ALERT(d_logger,msg);};
+ void fatal(std::string msg){GR_LOG_FATAL(d_logger,msg);};
+ void emerg(std::string msg){GR_LOG_EMERG(d_logger,msg);};
+ void errorIF(bool cond,std::string msg){GR_LOG_ERRORIF(d_logger,cond,msg);};
+ void log_assert(bool cond,std::string msg){GR_LOG_ASSERT(d_logger,cond,msg);};
+ void add_console_appender(std::string target,std::string pattern);
+ void add_file_appender(std::string filename,bool append,std::string pattern);
+ void add_rollingfile_appender(std::string filename,size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern);
};
-#endif /* HAVE_LOG4CPP */
-#endif /* ENABLE_GR_LOG */
+