diff options
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/CMakeLists.txt | 31 | ||||
-rw-r--r-- | gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc | 24 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gnuradio-core.rc.in | 55 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_pdu.h | 13 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.cc | 47 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_logger.cc | 189 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_logger.h | 498 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_logger.i | 96 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_logger.cc | 51 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_logger.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 | 12 |
17 files changed, 1064 insertions, 25 deletions
diff --git a/gnuradio-core/src/lib/CMakeLists.txt b/gnuradio-core/src/lib/CMakeLists.txt index 89a1bad88b..fe3e530869 100644 --- a/gnuradio-core/src/lib/CMakeLists.txt +++ b/gnuradio-core/src/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Free Software Foundation, Inc. +# Copyright 2010-2011,2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -39,6 +39,21 @@ list(APPEND gnuradio_core_sources bug_work_around_6.cc) list(APPEND test_gnuradio_core_sources bug_work_around_6.cc) ######################################################################## +# Set up Windows DLL resource files +######################################################################## + +IF(MSVC) + include(${CMAKE_SOURCE_DIR}/cmake/Modules/GrVersion.cmake) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio-core.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-core.rc + @ONLY) + + list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-core.rc) +ENDIF(MSVC) + +######################################################################## # Setup the include and linker paths ######################################################################## include_directories( @@ -54,13 +69,25 @@ 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) @@ -101,6 +128,6 @@ include_directories(${CPPUNIT_INCLUDE_DIRS}) 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}) +target_link_libraries(test-gnuradio-core gnuradio-core ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES} ${LOG4CXX_LIBRARIES}) 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..95e17123c8 100644 --- a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc +++ b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc @@ -48,6 +48,7 @@ // #include <gr_fir_sss_mmx.h> // #include <gr_fir_sss_sse2.h> + #include <iostream> using std::cerr; @@ -207,7 +208,7 @@ gr_fir_sysconfig_x86::create_gr_fir_fcc (const std::vector<gr_complex> &taps) if (gr_cpu::has_3dnow ()){ if (first){ - cerr << ">>> gr_fir_fcc: using 3DNow!\n"; + cerr << ">>> gr_fir_fcc: gr_fir_fcc: using 3DNow!\n"; first = false; } return make_gr_fir_fcc_3dnow (taps); @@ -215,7 +216,7 @@ 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"; + cerr << ">>> gr_fir_fcc: gr_fir_fcc: using SSE\n"; first = false; } return make_gr_fir_fcc_sse (taps); @@ -326,19 +327,26 @@ 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; if (gr_cpu::has_sse2 ()){ - cerr << ">>> gr_fir_sss: using SSE2\n"; - return make_gr_fir_sss_sse2 (taps); + if(first) { + cerr << ">>> gr_fir_sss: using SSE2\n"; + 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) { + cerr << ">>> gr_fir_sss: using MMX\n"; + 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) { + cerr << ">>> gr_fir_sss: handing off to parent class\n"; + return gr_fir_sysconfig_generic::create_gr_fir_sss (taps); + } } #endif diff --git a/gnuradio-core/src/lib/gnuradio-core.rc.in b/gnuradio-core/src/lib/gnuradio-core.rc.in new file mode 100644 index 0000000000..a5579ce4ed --- /dev/null +++ b/gnuradio-core/src/lib/gnuradio-core.rc.in @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 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. + */ + +#include <afxres.h> + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @MAJOR_VERSION@,@API_COMPAT@,@RC_MINOR_VERSION@,@RC_MAINT_VERSION@ + PRODUCTVERSION @MAJOR_VERSION@,@API_COMPAT@,@RC_MINOR_VERSION@,@RC_MAINT_VERSION@ + FILEFLAGSMASK 0x3fL +#ifndef NDEBUG + FILEFLAGS 0x0L +#else + FILEFLAGS 0x1L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE VFT2_DRV_INSTALLABLE + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "gnuradio-core" + VALUE "FileVersion", "@VERSION@" + VALUE "InternalName", "gnuradio-core.dll" + VALUE "LegalCopyright", "Licensed under GPLv3 or any later version" + VALUE "OriginalFilename", "gnuradio-core.dll" + VALUE "ProductName", "gnuradio-core" + VALUE "ProductVersion", "@VERSION@" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END + END diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h index a5ae87db7f..53058ccb6c 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.h +++ b/gnuradio-core/src/lib/io/gr_pdu.h @@ -23,17 +23,18 @@ #ifndef GR_PDU_H #define GR_PDU_H +#include <gr_core_api.h> #include <gr_complex.h> #include <gruel/pmt.h> -#define pdu_port_id pmt::mp("pdus") -#define pdu_length_tag pmt::mp("pdu_length") +#define PDU_PORT_ID pmt::mp("pdus") +#define PDU_LENGTH_TAG pmt::mp("pdu_length") enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex }; -size_t gr_pdu_itemsize(gr_pdu_vector_type type); -bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); -pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items); -gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector); +GR_CORE_API size_t gr_pdu_itemsize(gr_pdu_vector_type type); +GR_CORE_API bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); +GR_CORE_API pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items); +GR_CORE_API gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector); #endif diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc index 5c319dc39d..a702b66a2b 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc @@ -49,7 +49,7 @@ gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t) gr_make_io_signature(1, 1, gr_pdu_itemsize(t))), d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)) { - message_port_register_in(pdu_port_id); + message_port_register_in(PDU_PORT_ID); } gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream() @@ -77,8 +77,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items, if(noutput_items > 0){ // grab a message if one exists - //pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) ); - pmt::pmt_t msg( delete_head_blocking( pdu_port_id ) ); + //pmt::pmt_t msg( delete_head_nowait( PDU_PORT_ID ) ); + pmt::pmt_t msg( delete_head_blocking( PDU_PORT_ID ) ); if(msg.get() == NULL ){ return nout; } @@ -99,7 +99,7 @@ gr_pdu_to_tagged_stream::work(int noutput_items, uint64_t offset = nitems_written(0) + nout; // add a tag for pdu length - add_item_tag(0, offset, pdu_length_tag, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias())); + add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias())); // if we recieved metadata add it as tags if( !pmt_eq(meta, pmt::PMT_NIL) ){ diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc index 8211b7672d..1b869edfab 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc @@ -49,7 +49,7 @@ gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t) d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false), d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL) { - message_port_register_out(pdu_port_id); + message_port_register_out(PDU_PORT_ID); } gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu() @@ -70,7 +70,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items, get_tags_in_range(d_tags, 0, abs_N, abs_N+1); bool found_length_tag(false); for(d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++){ - if( pmt::pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){ + if( pmt::pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){ if( (*d_tags_itr).offset != abs_N ){ throw std::runtime_error("expected next pdu length tag on a different item..."); } @@ -91,7 +91,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items, // copy any tags in this range into our meta object get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy); for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++){ - if( ! pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){ + if( ! pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){ d_pdu_meta = pmt_dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); } } @@ -127,7 +127,7 @@ void gr_tagged_stream_to_pdu::send_message(){ } pmt::pmt_t msg = pmt::pmt_cons( d_pdu_meta, d_pdu_vector ); - message_port_pub( pdu_port_id, msg ); + message_port_pub( PDU_PORT_ID, msg ); d_pdu_meta = pmt::PMT_NIL; d_pdu_vector = pmt::PMT_NIL; diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 70938a0f17..6772f7a26d 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -62,6 +62,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_logger.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc @@ -105,6 +106,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_logger.cc ) ######################################################################## @@ -126,6 +128,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_logger.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.h @@ -170,6 +173,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_logger.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.i @@ -184,4 +188,5 @@ install(FILES DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig" ) + endif(ENABLE_PYTHON) diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 54d2676203..6c2ec4c539 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::debug :%p: %c{1} - %m%n", "System.out"); + } + else if(debug_file == "stderr") { + GR_LOG_ADD_CONSOLE_APPENDER(DLOG, "gr::debug :%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 () diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 0783e86848..e4b30267e6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -26,6 +26,7 @@ #include <gr_core_api.h> #include <gr_basic_block.h> #include <gr_tags.h> +#include <gr_logger.h> /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -616,6 +617,11 @@ class GR_CORE_API gr_block : public gr_basic_block { */ gruel::mutex d_setlock; + /*! Used by blocks to access the logger system. + */ + gr_logger_ptr d_logger; + gr_logger_ptr d_debug_logger; + // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friend GR_CORE_APIs diff --git a/gnuradio-core/src/lib/runtime/gr_logger.cc b/gnuradio-core/src/lib/runtime/gr_logger.cc new file mode 100644 index 0000000000..e337920a33 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_logger.cc @@ -0,0 +1,189 @@ +/* -*- 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 Johns Hopkins University Applied Physics Lab +* Author: Mark Plett +* Description: +* The gr_log module wraps the log4cxx library for logging in gnuradio. +*******************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_logger.h> +#include <stdexcept> +#include <algorithm> + +#ifdef ENABLE_GR_LOG +#ifdef HAVE_LOG4CXX + +bool gr_logger_configured(false); + +void +logger_load_config(const std::string &config_filename) +{ + if(!gr_logger_configured) { + gr_logger_configured = true; + if(config_filename.size() > 0) { + if(config_filename.find(".xml") != std::string::npos) { + log4cxx::xml::DOMConfigurator::configure(config_filename); + } + else { + log4cxx::PropertyConfigurator::configure(config_filename); + } + } + } +} + +void +logger_load_config_and_watch(const std::string &config_filename, + unsigned int watch_period) +{ + if(!gr_logger_configured) { + gr_logger_configured = true; + if(config_filename.size() > 0) { + if(config_filename.find(".xml") != std::string::npos) { + log4cxx::xml::DOMConfigurator::configureAndWatch(config_filename, watch_period); + } + else { + log4cxx::PropertyConfigurator::configureAndWatch(config_filename, watch_period); + } + } + } +} + +void +logger_reset_config(void) +{ + log4cxx::LogManager::resetConfiguration(); + gr_logger_configured=false; +} + +void +logger_set_level(gr_logger_ptr 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(gr_logger_ptr logger, log4cxx::LevelPtr level) +{ + logger->setLevel(level); +} + +void +logger_get_level(gr_logger_ptr logger, std::string &level) +{ + log4cxx::LevelPtr levelPtr = logger->getLevel(); + if(levelPtr == log4cxx::Level::getOff()) level = "off"; + if(levelPtr == log4cxx::Level::getAll()) level = "all"; + if(levelPtr == log4cxx::Level::getTrace()) level = "trace"; + if(levelPtr == log4cxx::Level::getDebug()) level = "debug"; + if(levelPtr == log4cxx::Level::getInfo()) level = "info"; + if(levelPtr == log4cxx::Level::getWarn()) level = "warn"; + if(levelPtr == log4cxx::Level::getError()) level = "error"; + if(levelPtr == log4cxx::Level::getFatal()) level = "fatal"; +}; + +void +logger_get_level(gr_logger_ptr logger, log4cxx::LevelPtr level) +{ + level = logger->getLevel(); +} + +void +logger_add_console_appender(gr_logger_ptr logger, std::string layout, + std::string target) +{ + log4cxx::PatternLayout *playout = + new log4cxx::PatternLayout(layout); + log4cxx::ConsoleAppender *appender = + new log4cxx::ConsoleAppender(log4cxx::LayoutPtr(playout), target); + log4cxx::helpers::Pool p; + appender->activateOptions(p); + logger->addAppender(appender); +} + +void +logger_add_file_appender(gr_logger_ptr logger, std::string layout, + std::string filename, bool append) +{ + log4cxx::PatternLayout *playout = + new log4cxx::PatternLayout(layout); + log4cxx::FileAppender *appender = + new log4cxx::FileAppender(log4cxx::LayoutPtr(playout), filename, append); + log4cxx::helpers::Pool p; + appender->activateOptions(p); + logger->addAppender(appender); +} + +void +logger_add_rollingfile_appender(gr_logger_ptr logger, std::string layout, + std::string filename, bool append, + int bkup_index, std::string filesize) +{ + log4cxx::PatternLayout *playout = + new log4cxx::PatternLayout(layout); + log4cxx::RollingFileAppender *appender = + new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(playout), filename, append); + appender->setMaxBackupIndex(bkup_index); + appender->setMaxFileSize(filesize); + log4cxx::helpers::Pool p; + appender->activateOptions(p); + logger->addAppender(appender); +} + +void +logger_get_logger_names(std::vector<std::string>& names) +{ + log4cxx::LoggerList list = log4cxx::LogManager::getCurrentLoggers(); + log4cxx::LoggerList::iterator logger = list.begin(); + names.clear(); + for(; logger != list.end(); logger++) { + names.push_back((*logger)->getName()); + } +} + +#endif /* HAVE_LOG4CXX */ +#endif /* ENABLE_GR_LOGGER */ diff --git a/gnuradio-core/src/lib/runtime/gr_logger.h b/gnuradio-core/src/lib/runtime/gr_logger.h new file mode 100644 index 0000000000..40684ec9d0 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_logger.h @@ -0,0 +1,498 @@ +/* -*- 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 Johns Hopkins University Applied Physics Lab +* Author: Mark Plett +* Description: +* The gr_logger module wraps the log4cxx library for logging in gnuradio +*******************************************************************************/ + +#ifndef INCLUDED_GR_LOGGER_H +#define INCLUDED_GR_LOGGER_H + +/*! +* \file gr_logger.h +* \ingroup logging +* \brief GNURADIO logging wrapper for log4cxx library (C++ port of log4j) +* +*/ + +#include <gr_core_api.h> +#include <assert.h> +#include <iostream> + +#ifdef ENABLE_GR_LOG + +// We have three configurations... first logging to stdout/stderr +#ifndef HAVE_LOG4CXX +//#warning GR logging Enabled and using std::cout + +typedef std::string gr_logger_ptr; + +#define GR_LOG_DECLARE_LOGPTR(logger) +#define GR_LOG_ASSIGN_LOGPTR(logger,name) +#define GR_CONFIG_LOGGER(config) +#define GR_CONFIG_AND_WATCH_LOGGER(config) +#define GR_LOG_GETLOGGER(logger, name) +#define GR_SET_LEVEL(name, level) +#define GR_LOG_SET_LEVEL(logger, level) +#define GR_GET_LEVEL(name, level) +#define GR_LOG_GET_LEVEL(logger, level) +#define GR_ADD_CONSOLE_APPENDER(logger,layout) +#define GR_LOG_ADD_CONSOLE_APPENDER(logger,layout) +#define GR_ADD_FILE_APPENDER(logger,layout,filename,append) +#define GR_LOG_ADD_FILE_APPENDER(logger,layout,filename,append) +#define GR_ADD_ROLLINGFILE_APPENDER(logger,layout,filename,append,bkup_index,filesize) +#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,layout,filename,append,bkup_index,filesize) +#define GR_GET_LOGGER_NAMES(names) +#define GR_RESET_CONFIGURATION() +#define GR_TRACE(name, msg) std::cout<<"TRACE:"<<msg<<std::endl +#define GR_DEBUG(name, msg) std::cout<<"DEBUG:"<<msg<<std::endl +#define GR_INFO(name, msg) std::cout<<"INFO:"<<msg<<std::endl +#define GR_WARN(name, msg) std::cerr<<"WARN:"<<msg<<std::endl +#define GR_ERROR(name, msg) std::cerr<<"ERROR:"<<msg<<std::endl +#define GR_FATAL(name, msg) std::cerr<<"FATAL:"<<msg<<std::endl +#define GR_ERRORIF(name, cond, msg) if((cond)) std::cerr<<"ERROR:"<<msg<<std::endl +#define GR_ASSERT(name, cond, msg) std::cerr<<"ERROR:"<<msg<<std::endl; assert(cond) +#define GR_LOG_SET_LEVEL(logger, level) +#define GR_LOG_GET_LEVEL(logger, level) +#define GR_LOG_TRACE(logger, msg) std::cout<<"TRACE:"<<msg<<std::endl +#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_WARN(logger, msg) std::cerr<<"WARN:"<<msg<<std::endl +#define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR:"<<msg<<std::endl +#define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL:"<<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) + +#else /* HAVE_LOG4CXX */ +// Second configuration...logging to log4cxx +//#warning GR logging Enabled and using LOG4CXX + +#include <log4cxx/logger.h> +#include <log4cxx/logmanager.h> +#include <log4cxx/basicconfigurator.h> +#include <log4cxx/xml/domconfigurator.h> +#include <log4cxx/propertyconfigurator.h> +#include <log4cxx/helpers/pool.h> +#include <log4cxx/fileappender.h> +#include <log4cxx/rollingfileappender.h> +#include <log4cxx/consoleappender.h> +#include <log4cxx/patternlayout.h> + +/*! + * \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 + */ + +typedef log4cxx::LoggerPtr gr_logger_ptr; + +/* Macros for Programmatic Configuration */ +#define GR_LOG_DECLARE_LOGPTR(logger) \ + gr_logger_ptr logger; + +#define GR_LOG_ASSIGN_LOGPTR(logger,name) \ + logger = gr_logger::getLogger(name); + +#define GR_CONFIG_LOGGER(config) \ + logger_load_config(config) + +#define GR_CONFIG_AND_WATCH_LOGGER(config,period) \ + logger_load_config_and_watch(config,period) + +#define GR_LOG_GETLOGGER(logger, name) \ + log4cxx::LoggerPtr logger = gr_logger::getLogger(name); + +#define GR_SET_LEVEL(name, level){ \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + logger_set_level(logger, level);} + +#define GR_LOG_SET_LEVEL(logger, level) \ + logger_set_level(logger, level); + +#define GR_GET_LEVEL(name, level){ \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + logger_get_level(logger,level);} + +#define GR_LOG_GET_LEVEL(logger, level) \ + logger_get_level(logger,level); + +#define GR_ADD_CONSOLE_APPENDER(name,layout,terget){d \ + gr_logger_ptr logger = log4cxx::Logger::getLogger(name); \ + logger_add_console_appender(logger,layout, target);} + +#define GR_LOG_ADD_CONSOLE_APPENDER(logger,layout,target){ \ + logger_add_console_appender(logger,layout,target);} + +#define GR_ADD_FILE_APPENDER(name,layout,filename,append){\ + gr_logger_ptr logger = log4cxx::Logger::getLogger(name); \ + logger_add_file_appender(logger,layout,filename,append);} + +#define GR_LOG_ADD_FILE_APPENDER(logger,layout,filename,append){\ + logger_add_file_appender(logger,layout,filename,append);} + +#define GR_ADD_ROLLINGFILE_APPENDER(name,layout,filename,append,bkup_index,filesize){\ + gr_logger_ptr logger = log4cxx::Logger::getLogger(name); \ + logger_add_rollingfile_appender(logger,layout,filename,append,bkup_index,filesize);} + +#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,layout,filename,append,bkup_index,filesize){\ + logger_add_rollingfile_appender(logger,layout,filename,append,bkup_index,filesize);} + +#define GR_GET_LOGGER_NAMES(names){ \ + logger_get_logger_names(names);} + +#define GR_RESET_CONFIGURATION(){ \ + logger_reset_config();} + +/* Logger name referenced macros */ +#define GR_TRACE(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_TRACE(logger, msg);} + +#define GR_DEBUG(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_DEBUG(logger, msg);} + +#define GR_INFO(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_INFO(logger, msg);} + +#define GR_WARN(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_WARN(logger, msg);} + +#define GR_ERROR(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_ERROR(logger, msg);} + +#define GR_FATAL(name, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_FATAL(logger, msg);} + +#define GR_ERRORIF(name, cond, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); \ + LOG4CXX_ASSERT(logger, !(cond), msg);} + +#define GR_ASSERT(name, cond, msg) { \ + log4cxx::LoggerPtr logger = log4cxx::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=""); + + +GR_CORE_API void logger_load_config_and_watch(const std::string &config_filename, + unsigned int watch_period); + +GR_CORE_API void logger_reset_config(void); + +/*! + * \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(gr_logger_ptr 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 + */ +GR_CORE_API void logger_set_level(gr_logger_ptr logger, log4cxx::LevelPtr level); + + +/*! + * \brief Get the logger's output level. + * + * Gets the level of the logger. This returns a string that + * corresponds 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 get the level of. + * \param level string to get the level into. + */ +GR_CORE_API void logger_get_level(gr_logger_ptr logger, std::string &level); + +/*! + * \brief Get the logger's output level. + * + * Gets the level of the logger. This returns 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 get the level of. + */ +GR_CORE_API void logger_get_level(gr_logger_ptr logger, log4cxx::LevelPtr level); + + +GR_CORE_API void logger_add_console_appender(gr_logger_ptr logger, std::string layout, + std::string target); + +GR_CORE_API void logger_add_file_appender(gr_logger_ptr logger, std::string layout, + std::string filename, bool append); + +GR_CORE_API void logger_add_rollingfile_appender(gr_logger_ptr logger, std::string layout, + std::string filename, bool append, + int bkup_index, std::string filesize); + +GR_CORE_API void logger_get_logger_names(std::vector<std::string>& names); + +/*! + * \brief instantiate (configure) logger. + * \ingroup logging + * + */ +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 + if(config_filename.find(".xml")!=std::string::npos) { + log4cxx::xml::DOMConfigurator::configureAndWatch(config_filename, watchPeriodSec); + } + else { + log4cxx::PropertyConfigurator::configureAndWatch(config_filename, watchPeriodSec); + } + }; + + static log4cxx::LoggerPtr getLogger(std::string name) + { + if(log4cxx::LogManager::exists(name)) { + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); + return logger; + } + else { + log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name); + logger->setLevel(log4cxx::Level::getOff()); + 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 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);}; + + // Wrappers for Logger Pointer referenced functions + /*! \brief inline function, wrapper to set the logger level */ + void set_log_level(log4cxx::LoggerPtr logger,std::string level){GR_LOG_SET_LEVEL(logger,level);} + + /*! \brief inline function, wrapper to get the logger level */ + void get_log_level(log4cxx::LoggerPtr logger,std::string &level){GR_LOG_GET_LEVEL(logger,level);} + + /*! \brief inline function, wrapper for LOG4CXX_TRACE for TRACE message */ + void log_trace(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_TRACE(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_DEBUG for DEBUG message */ + void log_debug(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_DEBUG(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_INFO for INFO message */ + void log_info(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_INFO(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_WARN for WARN message */ + void log_warn(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_WARN(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ERROR for ERROR message */ + void log_error(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_ERROR(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_FATAL for FATAL message */ + void log_fatal(log4cxx::LoggerPtr logger,std::string msg){GR_LOG_FATAL(logger,msg);}; + + /*! \brief inline function, wrapper for LOG4CXX_ASSERT for conditional ERROR message */ + void log_errorIF(log4cxx::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(log4cxx::LoggerPtr logger,bool cond,std::string msg){GR_LOG_ASSERT(logger,cond,msg);}; +}; + + +#endif /* HAVE_LOG4CXX */ + +// If Logger disable do nothing +#else /* ENABLE_GR_LOG */ + +typedef void* gr_logger_ptr; + +#define GR_LOG_DECLARE_LOGPTR(logger) +#define GR_LOG_ASSIGN_LOGPTR(logger,name) +#define GR_CONFIG_LOGGER(config) +#define GR_CONFIG_AND_WATCH_LOGGER(config) +#define GR_LOG_GETLOGGER(logger, name) +#define GR_SET_LEVEL(name, level) +#define GR_LOG_SET_LEVEL(logger, level) +#define GR_GET_LEVEL(name, level) +#define GR_LOG_GET_LEVEL(logger, level) +#define GR_ADD_CONSOLE_APPENDER(logger,layout) +#define GR_LOG_ADD_CONSOLE_APPENDER(logger,layout) +#define GR_ADD_FILE_APPENDER(logger,layout,filename,append) +#define GR_LOG_ADD_FILE_APPENDER(logger,layout) +#define GR_ADD_ROLLINGFILE_APPENDER(logger,layout,filename,append,bkup_index,filesize) +#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,layout) +#define GR_GET_LOGGER_NAMES(names) +#define GR_RESET_CONFIGURATION() +#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_SET_LEVEL(logger, level) +#define GR_LOG_GET_LEVEL(logger, level) +#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_LOGGER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_logger.i b/gnuradio-core/src/lib/runtime/gr_logger.i new file mode 100644 index 0000000000..1eedf3d60d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_logger.i @@ -0,0 +1,96 @@ +/* -*- 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 Johns Hopkins University Applied Physics Lab +* Author: Mark Plett +* Description: +* SWIG interface generator file for gr_logger module. gr_logger 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 +#ifdef HAVE_LOG4CXX + +%{ +// The .h files +#include <gr_logger.h> +#include <log4cxx/logger.h> +#include <log4cxx/logmanager.h> +%} + +namespace log4cxx{ +class LoggerPtr { +public: + ~LoggerPtr(); +}; +}; +void logger_load_config(const std::string &config_filename); +void logger_set_level(log4cxx::LoggerPtr logger, const std::string &level); + +%rename(log) gr_logger; + +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 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 log4cxx::LoggerPtr getLogger(std::string name); + + void set_log_level(log4cxx::LoggerPtr logger,std::string level); + void get_log_level(log4cxx::LoggerPtr logger,std::string &level); + void log_trace(log4cxx::LoggerPtr logger,std::string msg); + void log_debug(log4cxx::LoggerPtr logger,std::string msg); + void log_info(log4cxx::LoggerPtr logger,std::string msg); + void log_warn(log4cxx::LoggerPtr logger,std::string msg); + void log_error(log4cxx::LoggerPtr logger,std::string msg); + void log_fatal(log4cxx::LoggerPtr logger,std::string msg); + void log_errorIF(log4cxx::LoggerPtr logger,bool cond,std::string msg); + void log_assert(log4cxx::LoggerPtr logger,bool cond,std::string msg); +}; + +#endif /* HAVE_LOG4CXX */ +#endif /* ENABLE_GR_LOG */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_logger.cc b/gnuradio-core/src/lib/runtime/qa_gr_logger.cc new file mode 100644 index 0000000000..3d21c1f305 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_logger.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_logger.h> +#include <gr_logger.h> + +void +qa_gr_logger::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_logger.h b/gnuradio-core/src/lib/runtime/qa_gr_logger.h new file mode 100644 index 0000000000..b0d3711523 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_logger.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_logger : public CppUnit::TestCase { + public: + CPPUNIT_TEST_SUITE(qa_gr_logger); + 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..62c95ef5c4 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_logger.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_logger::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..8902c6103f 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_logger.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_logger.i> diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt index d8a64cc0f6..de42cf2a49 100644 --- a/gnuradio-core/src/lib/swig/CMakeLists.txt +++ b/gnuradio-core/src/lib/swig/CMakeLists.txt @@ -25,9 +25,19 @@ set(GR_SWIG_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${GNURADIO_CORE_SWIG_INCLUDE_DIRS} ${GRUEL_INCLUDE_DIRS} + ${LOG4CXX_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) -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) link_directories(${Boost_LIBRARY_DIRS}) |