diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-06-13 09:50:09 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-06-13 09:50:09 -0400 |
commit | 9e299d568123f8df5188d0850311cb7f5b5e11f2 (patch) | |
tree | 00763566d97871a7c5bb5a2410af8f97c2299684 /gnuradio-core | |
parent | a87c609beb6aef9b584c7ff638cdffe7e3637e97 (diff) |
log: added a macro and routine to set log level from config file.
Also worked on documentation of logging features.
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc | 14 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.cc | 35 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.h | 65 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.i | 5 |
4 files changed, 118 insertions, 1 deletions
diff --git a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc index 4e3598c5d4..a218015154 100644 --- a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc +++ b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc @@ -178,8 +178,10 @@ gr_fir_sysconfig_x86::create_gr_fir_ccf (const std::vector<float> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnow ()){ if (first){ @@ -210,8 +212,10 @@ gr_fir_sysconfig_x86::create_gr_fir_fcc (const std::vector<gr_complex> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnow ()){ if (first){ @@ -242,8 +246,10 @@ gr_fir_sysconfig_x86::create_gr_fir_ccc (const std::vector<gr_complex> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnowext ()){ if (first) { @@ -282,8 +288,10 @@ gr_fir_sysconfig_x86::create_gr_fir_fff (const std::vector<float> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnow ()){ if (first) { @@ -314,8 +322,10 @@ gr_fir_sysconfig_x86::create_gr_fir_fsf (const std::vector<float> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnow ()){ if (first) { @@ -349,8 +359,10 @@ gr_fir_sysconfig_x86::create_gr_fir_sss (const std::vector<short> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_sse2 ()){ if(first) { @@ -379,8 +391,10 @@ gr_fir_sysconfig_x86::create_gr_fir_scc (const std::vector<gr_complex> &taps) static bool first = true; std::string log_file = gr_prefs::singleton()->get_string("LOG", "log_config", ""); + std::string log_level = gr_prefs::singleton()->get_string("LOG", "log_level", "off"); GR_CONFIG_LOGGER(log_file); GR_LOG_GETLOGGER(LOG, "gr_log.gr_fir_sysconfig_x86"); + GR_LOG_SET_LEVEL(LOG, log_level); if (gr_cpu::has_3dnowext ()){ if (first){ diff --git a/gnuradio-core/src/lib/runtime/gr_log.cc b/gnuradio-core/src/lib/runtime/gr_log.cc index 7af55b155c..9be3ba04fd 100644 --- a/gnuradio-core/src/lib/runtime/gr_log.cc +++ b/gnuradio-core/src/lib/runtime/gr_log.cc @@ -38,6 +38,9 @@ #endif #include <gr_log.h> +#include <stdexcept> +#include <algorithm> + void logger_load_config(const std::string &config_filename) @@ -52,3 +55,35 @@ logger_load_config(const std::string &config_filename) PropertyConfigurator::configure(config_filename); } } + +void +logger_set_level(LoggerPtr logger, const std::string &level) +{ + std::string nocase = level; + std::transform(level.begin(), level.end(), nocase.begin(), ::tolower); + + if(nocase == "off") + logger_set_level(logger, log4cxx::Level::getOff()); + else if(nocase == "all") + logger_set_level(logger, log4cxx::Level::getAll()); + else if(nocase == "trace") + logger_set_level(logger, log4cxx::Level::getTrace()); + else if(nocase == "debug") + logger_set_level(logger, log4cxx::Level::getDebug()); + else if(nocase == "info") + logger_set_level(logger, log4cxx::Level::getInfo()); + else if(nocase == "warn") + logger_set_level(logger, log4cxx::Level::getWarn()); + else if(nocase == "error") + logger_set_level(logger, log4cxx::Level::getError()); + else if(nocase == "fatal") + logger_set_level(logger, log4cxx::Level::getFatal()); + else + throw std::runtime_error("logger_set_level: Bad level type.\n"); +} + +void +logger_set_level(LoggerPtr logger, log4cxx::LevelPtr level) +{ + logger->setLevel(level); +} diff --git a/gnuradio-core/src/lib/runtime/gr_log.h b/gnuradio-core/src/lib/runtime/gr_log.h index 9050b70eb3..e932257a32 100644 --- a/gnuradio-core/src/lib/runtime/gr_log.h +++ b/gnuradio-core/src/lib/runtime/gr_log.h @@ -74,6 +74,13 @@ using namespace log4cxx::helpers; #define GR_LOG_GETLOGGER(logger, name) \ LoggerPtr logger = gr_log::getLogger(name); +#define GR_LOG_SET_LEVEL(logger, level) \ + logger_set_level(logger, level); + +#define GR_SET_LEVEL(name, level) \ + LoggerPtr logger = Logger::getLogger(name); \ + logger_set_level(logger, level); + /* Logger name referenced macros */ #define GR_TRACE(name, msg) { \ LoggerPtr logger = Logger::getLogger(name); \ @@ -135,10 +142,58 @@ using namespace log4cxx::helpers; assert(cond);} -// Load configuration file +/*! + * \brief Load logger's configuration file. + * + * Initialize the GNU Radio logger by loading the configuration file + * \p config_filename. + * + * \param config_filename The configuration file. Set to "" for the + * basic logger that outputs to the console. + */ void logger_load_config(const std::string &config_filename=""); /*! + * \brief Set the logger's output level. + * + * Sets the level of the logger. This takes a string that is + * translated to the standard levels and can be (case insensitive): + * + * \li off + * \li all + * \li trace + * \li debug + * \li info + * \li warn + * \li error + * \li fatal + * + * \param logger the logger to set the level of. + * \param level string to set the level to. + */ +void logger_set_level(LoggerPtr logger, const std::string &level); + +/*! + * \brief Set the logger's output level. + * + * Sets the level of the logger. This takes the actual Log4cxx::Level + * data type, which can be: + * + * \li Log4cxx::Level::getOff() + * \li Log4cxx::Level::getAll() + * \li Log4cxx::Level::getTrace() + * \li Log4cxx::Level::getDebug() + * \li Log4cxx::Level::getInfo() + * \li Log4cxx::Level::getWarn() + * \li Log4cxx::Level::getError() + * \li Log4cxx::Level::getFatal() + * + * \param logger the logger to set the level of. + * \param level new logger level of type Log4cxx::Level + */ +void logger_set_level(LoggerPtr logger, log4cxx::LevelPtr level); + +/*! * \brief instantiate (configure) logger. * \ingroup logging * @@ -175,6 +230,9 @@ class gr_log return logger; }; + /*! \brief inline function, wrapper to set the logger level */ + void set_level(std::string name,std::string level){GR_SET_LEVEL(name,level);} + // Wrappers for logging macros /*! \brief inline function, wrapper for LOG4CXX_TRACE for TRACE message */ void trace(std::string name,std::string msg){GR_TRACE(name,msg);}; @@ -200,6 +258,10 @@ class gr_log /*! \brief inline function, wrapper for LOG4CXX_ASSERT for conditional ERROR message */ void gr_assert(std::string name,bool cond,std::string msg){GR_ASSERT(name,cond,msg);}; + + /*! \brief inline function, wrapper to set the logger level */ + void set_log_level(LoggerPtr logger,std::string level){GR_LOG_SET_LEVEL(logger,level);} + /*! \brief inline function, wrapper for LOG4CXX_TRACE for TRACE message */ void log_trace(LoggerPtr logger,std::string msg){GR_LOG_TRACE(logger,msg);}; @@ -231,6 +293,7 @@ class gr_log #define GR_CONFIG_LOGGER(config) #define GR_LOG_GETLOGGER(logger, name) +#define GR_LOG_SET_LEVEL(logger, level) #define GR_TRACE(name, msg) #define GR_DEBUG(name, msg) #define GR_INFO(name, msg) diff --git a/gnuradio-core/src/lib/runtime/gr_log.i b/gnuradio-core/src/lib/runtime/gr_log.i index e539c5528b..4c9cc4f255 100644 --- a/gnuradio-core/src/lib/runtime/gr_log.i +++ b/gnuradio-core/src/lib/runtime/gr_log.i @@ -54,6 +54,9 @@ public: ~LoggerPtr(); }; +void logger_load_config(const std::string &config_filename); +void logger_set_level(LoggerPtr logger, const std::string &level); + class gr_log { private: @@ -61,6 +64,7 @@ private: public: // gr_log(std::string config_filename); gr_log(std::string config_filename,int watchPeriodSec); + void set_level(std::string name,std::string level); void trace(std::string name,std::string msg); void debug(std::string name,std::string msg); void info(std::string name,std::string msg); @@ -72,6 +76,7 @@ public: static LoggerPtr getLogger(std::string name); + void set_log_level(LoggerPtr logger,std::string level); void log_trace(LoggerPtr logger,std::string msg); void log_debug(LoggerPtr logger,std::string msg); void log_info(LoggerPtr logger,std::string msg); |