diff options
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/CMakeLists.txt | 16 | ||||
-rw-r--r-- | gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc | 105 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.cc | 92 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.h | 316 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_log.i | 92 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_log.cc | 51 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_log.h | 42 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/runtime.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/swig/CMakeLists.txt | 15 |
11 files changed, 709 insertions, 29 deletions
diff --git a/gnuradio-core/src/lib/CMakeLists.txt b/gnuradio-core/src/lib/CMakeLists.txt index 9c980157db..30cd5897bb 100644 --- a/gnuradio-core/src/lib/CMakeLists.txt +++ b/gnuradio-core/src/lib/CMakeLists.txt @@ -50,13 +50,25 @@ link_directories(${Boost_LIBRARY_DIRS}) include_directories(${FFTW3F_INCLUDE_DIRS}) link_directories(${FFTW3F_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## + +# Only use if log4cxx is installed +# Define ENABLE_GR_LOG so .h and .cc files can turn actual +# logging and insert dummy functions. +#if(LOG4CXX_FOUND) +# add_definitions(-DENABLE_GR_LOG) +#endif(LOG4CXX_FOUND) + list(APPEND gnuradio_core_libs gruel ${Boost_LIBRARIES} ${FFTW3F_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) if(FFTW3F_THREADS_LIBRARIES) @@ -99,4 +111,8 @@ link_directories(${CPPUNIT_LIBRARY_DIRS}) add_library(test-gnuradio-core SHARED ${test_gnuradio_core_sources}) target_link_libraries(test-gnuradio-core gnuradio-core ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES}) +if(LOG4CXX_FOUND) + target_link_libraries(test-gnuradio-core gnuradio-core ${LOG4CXX_LIBRARIES}) +endif(LOG4CXX_FOUND) + endif(ENABLE_TESTING) 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 97b8106994..a218015154 100644 --- a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc +++ b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc @@ -48,8 +48,8 @@ // #include <gr_fir_sss_mmx.h> // #include <gr_fir_sss_sse2.h> -#include <iostream> -using std::cerr; +#include <gr_prefs.h> +#include <gr_log.h> /* * ---------------------------------------------------------------- @@ -177,9 +177,15 @@ 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){ - cerr << ">>> gr_fir_ccf: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccf: using 3DNow!"); first = false; } return make_gr_fir_ccf_3dnow (taps); @@ -187,14 +193,14 @@ gr_fir_sysconfig_x86::create_gr_fir_ccf (const std::vector<float> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_ccf: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccf: using SSE"); first = false; } return make_gr_fir_ccf_sse (taps); } if (first){ - cerr << ">>> gr_fir_ccf: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccf: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_ccf (taps); @@ -205,9 +211,15 @@ 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){ - cerr << ">>> gr_fir_fcc: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_fcc: gr_fir_fcc: using 3DNow!"); first = false; } return make_gr_fir_fcc_3dnow (taps); @@ -215,14 +227,14 @@ gr_fir_sysconfig_x86::create_gr_fir_fcc (const std::vector<gr_complex> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_fcc: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_fcc: gr_fir_fcc: using SSE"); first = false; } return make_gr_fir_fcc_sse (taps); } if (first){ - cerr << ">>> gr_fir_fcc: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_fcc: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_fcc (taps); @@ -233,9 +245,15 @@ 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) { - cerr << ">>> gr_fir_ccc: using 3DNow!Ext\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccc: using 3DNow!Ext"); first = false; } return make_gr_fir_ccc_3dnowext (taps); @@ -243,7 +261,7 @@ gr_fir_sysconfig_x86::create_gr_fir_ccc (const std::vector<gr_complex> &taps) if (gr_cpu::has_3dnow ()){ if (first) { - cerr << ">>> gr_fir_ccc: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccc: using 3DNow!"); first = false; } return make_gr_fir_ccc_3dnow (taps); @@ -251,14 +269,14 @@ gr_fir_sysconfig_x86::create_gr_fir_ccc (const std::vector<gr_complex> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_ccc: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccc: using SSE"); first = false; } return make_gr_fir_ccc_sse (taps); } if (first){ - cerr << ">>> gr_fir_ccc: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_ccc: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_ccc (taps); @@ -269,9 +287,15 @@ 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) { - cerr << ">>> gr_fir_fff: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_fff: using 3DNow!"); first = false; } return make_gr_fir_fff_3dnow (taps); @@ -279,14 +303,14 @@ gr_fir_sysconfig_x86::create_gr_fir_fff (const std::vector<float> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_fff: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_fff: using SSE"); first = false; } return make_gr_fir_fff_sse (taps); } if (first){ - cerr << ">>> gr_fir_fff: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_fff: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_fff (taps); @@ -297,9 +321,15 @@ 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) { - cerr << ">>> gr_fir_fsf: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_fsf: using 3DNow!"); first = false; } return make_gr_fir_fsf_3dnow (taps); @@ -307,14 +337,14 @@ gr_fir_sysconfig_x86::create_gr_fir_fsf (const std::vector<float> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_fsf: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_fsf: using SSE"); first = false; } return make_gr_fir_fsf_sse (taps); } if (first){ - cerr << ">>> gr_fir_fsf: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_fsf: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_fsf (taps); @@ -326,19 +356,32 @@ gr_fir_sysconfig_x86::create_gr_fir_sss (const std::vector<short> &taps) { // FIXME -- probably want to figure out best answer for Athlon and code // add code to select it here... + 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 ()){ - cerr << ">>> gr_fir_sss: using SSE2\n"; - return make_gr_fir_sss_sse2 (taps); + if(first) { + GR_LOG_TRACE(LOG, "gr_fir_sss: using SSE2"); + return make_gr_fir_sss_sse2 (taps); + } } if (gr_cpu::has_mmx ()){ - cerr << ">>> gr_fir_sss: using MMX\n"; - return make_gr_fir_sss_mmx (taps); + if(first) { + GR_LOG_TRACE(LOG, "gr_fir_sss: using MMX"); + return make_gr_fir_sss_mmx (taps); + } } - cerr << ">>> gr_fir_sss: handing off to parent class\n"; - return gr_fir_sysconfig_generic::create_gr_fir_sss (taps); + if(first) { + GR_LOG_TRACE(LOG, "gr_fir_sss: handing off to parent class"); + return gr_fir_sysconfig_generic::create_gr_fir_sss (taps); + } } #endif @@ -347,9 +390,15 @@ 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){ - cerr << ">>> gr_fir_scc: using 3DNow!Ext\n"; + GR_LOG_TRACE(LOG, "gr_fir_scc: using 3DNow!Ext"); first = false; } return make_gr_fir_scc_3dnowext (taps); @@ -357,7 +406,7 @@ gr_fir_sysconfig_x86::create_gr_fir_scc (const std::vector<gr_complex> &taps) if (gr_cpu::has_3dnow ()){ if (first){ - cerr << ">>> gr_fir_scc: using 3DNow!\n"; + GR_LOG_TRACE(LOG, "gr_fir_scc: using 3DNow!"); first = false; } return make_gr_fir_scc_3dnow (taps); @@ -365,14 +414,14 @@ gr_fir_sysconfig_x86::create_gr_fir_scc (const std::vector<gr_complex> &taps) if (gr_cpu::has_sse ()){ if (first){ - cerr << ">>> gr_fir_scc: using SSE\n"; + GR_LOG_TRACE(LOG, "gr_fir_scc: using SSE"); first = false; } return make_gr_fir_scc_sse (taps); } if (first){ - cerr << ">>> gr_fir_scc: handing off to parent class\n"; + GR_LOG_TRACE(LOG, "gr_fir_scc: handing off to parent class"); first = false; } return gr_fir_sysconfig_generic::create_gr_fir_scc (taps); diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 5f3672dde9..bb8d6068d9 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -61,6 +61,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_log.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc @@ -104,6 +105,7 @@ list(APPEND test_gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/qa_block_tags.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_runtime.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_set_msg_handler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_log.cc ) ######################################################################## @@ -124,6 +126,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_log.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.h @@ -168,6 +171,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_log.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.i @@ -182,4 +186,5 @@ install(FILES DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig" ) + endif(ENABLE_PYTHON) diff --git a/gnuradio-core/src/lib/runtime/gr_log.cc b/gnuradio-core/src/lib/runtime/gr_log.cc new file mode 100644 index 0000000000..cbf196cf0b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_log.cc @@ -0,0 +1,92 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +/* + * config.h is generated by configure. It contains the results + * of probing for features, options etc. It should be the first + * file included in your .cc file. + */ + +/************************************************ +* Johns Hopkins University Applied Physics Lab +* Author: Mark Plett (Adapted from gr_how_t0_write_a_block_3.2 +* Description: +* This block is a pass through to exercise the logging module gr.error_logger. +**************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_log.h> +#include <stdexcept> +#include <algorithm> + +#ifdef ENABLE_GR_LOG + +void +logger_load_config(const std::string &config_filename) +{ + if(config_filename.size() == 0) { + BasicConfigurator::configure(); + } + else if(config_filename.find(".xml") != std::string::npos) { + DOMConfigurator::configure(config_filename); + } + else { + 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); +} + +#endif /* ENABLE_GR_LOG */ diff --git a/gnuradio-core/src/lib/runtime/gr_log.h b/gnuradio-core/src/lib/runtime/gr_log.h new file mode 100644 index 0000000000..be01da1c6e --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_log.h @@ -0,0 +1,316 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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. + */ + +/************************************************ +* Copyright 2011 JHU APL +* Description: +* The gr_log module wraps the log4cxx library for logging in gnuradio +* +**************************************************/ + +#ifndef INCLUDED_GR_LOG_H +#define INCLUDED_GR_LOG_H + +/*! +* \file gr_log.h +* \ingroup logging +* \brief GNURADIO logging wrapper for log4cxx library (C++ port of log4j) +* +*/ + +#ifdef ENABLE_GR_LOG + +#include <gr_core_api.h> +#include <stdio.h> +#include <string> +#include <stdlib.h> +#include <assert.h> + +#include <log4cxx/logger.h> +#include <log4cxx/logmanager.h> +#include <log4cxx/basicconfigurator.h> +#include <log4cxx/xml/domconfigurator.h> +#include <log4cxx/propertyconfigurator.h> + +using namespace log4cxx; +using namespace log4cxx::xml; +using namespace log4cxx::helpers; + +/*! + * \brief GR_LOG macros + * \ingroup logging + * + * These macros wrap the standard LOG4CXX_LEVEL macros. The availablie macros + * are: + * GR_LOG_TRACE + * GR_LOG_DEBUG + * GR_LOG_INFO + * GR_LOG_WARN + * GR_LOG_ERROR + * GR_LOG_FATAL + */ + +#define GR_CONFIG_LOGGER(config) \ + logger_load_config(config) + +#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); \ + LOG4CXX_TRACE(logger, msg);} + +#define GR_DEBUG(name, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_DEBUG(logger, msg);} + +#define GR_INFO(name, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_INFO(logger, msg);} + +#define GR_WARN(name, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_WARN(logger, msg);} + +#define GR_ERROR(name, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_ERROR(logger, msg);} + +#define GR_FATAL(name, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_FATAL(logger, msg);} + +#define GR_ERRORIF(name, cond, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_ASSERT(logger, !(cond), msg);} + +#define GR_ASSERT(name, cond, msg) { \ + LoggerPtr logger = Logger::getLogger(name); \ + LOG4CXX_ASSERT(logger, cond, msg); \ + assert(cond);} + +/* LoggerPtr Referenced Macros */ +#define GR_LOG_TRACE(logger, msg) { \ + LOG4CXX_TRACE(logger, msg);} + +#define GR_LOG_DEBUG(logger, msg) { \ + LOG4CXX_DEBUG(logger, msg);} + +#define GR_LOG_INFO(logger, msg) { \ + LOG4CXX_INFO(logger, msg);} + +#define GR_LOG_WARN(logger, msg) { \ + LOG4CXX_WARN(logger, msg);} + +#define GR_LOG_ERROR(logger, msg) { \ + LOG4CXX_ERROR(logger, msg);} + +#define GR_LOG_FATAL(logger, msg) { \ + LOG4CXX_FATAL(logger, msg);} + +#define GR_LOG_ERRORIF(logger,cond, msg) { \ + LOG4CXX_ASSERT(logger, !(cond), msg);} + +#define GR_LOG_ASSERT(logger, cond, msg) { \ + LOG4CXX_ASSERT(logger, cond, msg); \ + assert(cond);} + + +/*! + * \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. + */ +GR_CORE_API 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. + */ +GR_CORE_API 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 + * + */ +class gr_log +{ + public: + /*! + * \brief contructor take log configuration file and configures loggers. + */ + gr_log(std::string config_filename) + { + // Load configuration file + logger_load_config(config_filename); + }; + + /*! + * \brief contructor take log configuration file and watchtime and configures + */ + gr_log(std::string config_filename, int watchPeriodSec) + { + // Load configuration file + if(config_filename.find(".xml")!=std::string::npos) { + DOMConfigurator::configureAndWatch(config_filename, watchPeriodSec); + } + else { + PropertyConfigurator::configureAndWatch(config_filename, watchPeriodSec); + } + }; + + static LoggerPtr getLogger(std::string name) + { + LoggerPtr logger = Logger::getLogger(name); + 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);}; + + /*! \brief inline function, wrapper for LOG4CXX_DEBUG for DEBUG message */ + void debug(std::string name,std::string msg){GR_DEBUG(name,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_INFO for INFO message */ + void info(std::string name,std::string msg){GR_INFO(name,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_WARN for WARN message */ + void warn(std::string name,std::string msg){GR_WARN(name,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ERROR for ERROR message */ + void error(std::string name,std::string msg){GR_ERROR(name,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_FATAL for FATAL message */ + void fatal(std::string name,std::string msg){GR_FATAL(name,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_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 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);}; + + /*! \brief inline function, wrapper for LOG4CXX_DEBUG for DEBUG message */ + void log_debug(LoggerPtr logger,std::string msg){GR_LOG_DEBUG(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_INFO for INFO message */ + void log_info(LoggerPtr logger,std::string msg){GR_LOG_INFO(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_WARN for WARN message */ + void log_warn(LoggerPtr logger,std::string msg){GR_LOG_WARN(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ERROR for ERROR message */ + void log_error(LoggerPtr logger,std::string msg){GR_LOG_ERROR(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_FATAL for FATAL message */ + void log_fatal(LoggerPtr logger,std::string msg){GR_LOG_FATAL(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ASSERT for conditional ERROR message */ + void log_errorIF(LoggerPtr logger,bool cond,std::string msg){GR_LOG_ERRORIF(logger,cond,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ASSERT for conditional ERROR message */ + void log_assert(LoggerPtr logger,bool cond,std::string msg){GR_LOG_ASSERT(logger,cond,msg);}; +}; + + +//If ENABLE_GR_LOG not set then clear all logging macros +#else + +#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) +#define GR_WARN(name, msg) +#define GR_ERROR(name, msg) +#define GR_FATAL(name, msg) +#define GR_ERRORIF(name, cond, msg) +#define GR_ASSERT(name, cond, msg) +#define GR_LOG_TRACE(logger, msg) +#define GR_LOG_DEBUG(logger, msg) +#define GR_LOG_INFO(logger, msg) +#define GR_LOG_WARN(logger, msg) +#define GR_LOG_ERROR(logger, msg) +#define GR_LOG_FATAL(logger, msg) +#define GR_LOG_ERRORIF(logger, cond, msg) +#define GR_LOG_ASSERT(logger, cond, msg) + +#endif /* ENABLE_GR_LOG */ +#endif /* INCLUDED_GR_LOG_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_log.i b/gnuradio-core/src/lib/runtime/gr_log.i new file mode 100644 index 0000000000..b0059e05f4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_log.i @@ -0,0 +1,92 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/******************************************************************************* +* +* Copyright 2011 JHU APL +* +* SWIG interface generator file for gr_log module. gr_log wraps log4cxx logging +* for gnuradio. +* +*******************************************************************************/ + +%feature("autodoc", "1"); // generate python docstrings + +%include "exception.i" +%import "gnuradio.i" // the common stuff + +%{ +#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix +#include <stdexcept> +%} + +//----------------------------------- + +#ifdef ENABLE_GR_LOG + +%{ +// The .h files +#include <gr_log.h> +#include <log4cxx/logger.h> +#include <log4cxx/logmanager.h> +%} + +class LoggerPtr { +public: + ~LoggerPtr(); +}; + +void logger_load_config(const std::string &config_filename); +void logger_set_level(LoggerPtr logger, const std::string &level); + +%rename(log) gr_log; + +class gr_log +{ +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); + void warn(std::string name,std::string msg); + void error(std::string name,std::string msg); + void fatal(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 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); + void log_warn(LoggerPtr logger,std::string msg); + void log_error(LoggerPtr logger,std::string msg); + void log_fatal(LoggerPtr logger,std::string msg); + void log_errorIF(LoggerPtr logger,bool cond,std::string msg); + void log_assert(LoggerPtr logger,bool cond,std::string msg); +}; + +#endif /* ENABLE_GR_LOG */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_log.cc b/gnuradio-core/src/lib/runtime/qa_gr_log.cc new file mode 100644 index 0000000000..a973408028 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_log.cc @@ -0,0 +1,51 @@ +/* + * Copyright 2012 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. + */ + +/* + * This class gathers together all the test cases for the example + * directory into a single test suite. As you create new test cases, + * add them here. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_log.h> +#include <gr_log.h> + +void +qa_gr_log::t1() +{ +#ifdef ENABLE_GR_LOG + // This doesn't really test anything, more just + // making sure nothing's gone horribly wrong. + GR_LOG_GETLOGGER(LOG,"errLoggerRoot"); + GR_LOG_TRACE(LOG,"test from c++ 1"); + GR_LOG_DEBUG(LOG,"test from c++ 1"); + GR_LOG_INFO(LOG,"test from c++ 1"); + GR_LOG_WARN(LOG,"test from c++ 1"); + GR_LOG_ERROR(LOG,"test from c++ 1"); + GR_LOG_FATAL(LOG,"test from c++ 1"); + GR_LOG_ERRORIF(LOG,2>1,"test from c++ 1"); + CPPUNIT_ASSERT(true); +#endif +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_log.h b/gnuradio-core/src/lib/runtime/qa_gr_log.h new file mode 100644 index 0000000000..75e96d2e7a --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_log.h @@ -0,0 +1,42 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 Example 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 Example Public License for more details. + * + * You should have received a copy of the GNU Example 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. + */ + +#ifndef INCLUDED_QA_GR_LOG_H +#define INCLUDED_QA_GR_LOG_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestSuite.h> + +//! collect all the tests for the example directory + +class qa_gr_log : public CppUnit::TestCase { + public: + CPPUNIT_TEST_SUITE(qa_gr_log); + CPPUNIT_TEST(t1); + CPPUNIT_TEST_SUITE_END(); + + private: + void t1(); + +}; + +#endif /* INCLUDED_QA_GR_LOG_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 5e62c79915..90b345c04f 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -34,6 +34,7 @@ #include <qa_gr_io_signature.h> #include <qa_gr_block.h> #include <qa_gr_flowgraph.h> +#include <qa_gr_log.h> #include <qa_gr_top_block.h> #include <qa_gr_hier_block2.h> #include <qa_gr_hier_block2_derived.h> @@ -50,6 +51,7 @@ qa_runtime::suite () s->addTest (qa_gr_io_signature::suite ()); s->addTest (qa_gr_block::suite ()); s->addTest (qa_gr_flowgraph::suite ()); + s->addTest (qa_gr_log::suite ()); s->addTest (qa_gr_top_block::suite ()); s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_hier_block2_derived::suite ()); diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 8e35df8342..9e0e378290 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -40,6 +40,7 @@ #include <gr_sync_decimator.h> #include <gr_sync_interpolator.h> #include <gr_top_block.h> +#include <gr_log.h> %} %constant int sizeof_char = sizeof(char); @@ -67,3 +68,4 @@ %include <gr_sync_decimator.i> %include <gr_sync_interpolator.i> %include <gr_top_block.i> +%include <gr_log.i> diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt index 5b740d916d..6d73babc7f 100644 --- a/gnuradio-core/src/lib/swig/CMakeLists.txt +++ b/gnuradio-core/src/lib/swig/CMakeLists.txt @@ -24,14 +24,27 @@ include(GrSwig) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + set(GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${GRUEL_INCLUDE_DIRS} + ${LOG4CXX_INCLUDE_DIRS} ${GNURADIO_CORE_SWIG_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ) -set(GR_SWIG_LIBRARIES gnuradio-core) +set(GR_SWIG_LIBRARIES + gnuradio-core + ${LOG4CXX_LIBRARIES} +) + +# Only use if log4cxx is installed +# Define ENABLE_GR_LOG for the .i file to ignore it. +if(ENABLE_GR_LOG) + SET(GR_SWIG_FLAGS "-DENABLE_GR_LOG") +endif(ENABLE_GR_LOG) ######################################################################## # Build and install the swig targets |