diff options
37 files changed, 1101 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 36c462e688..a3120d97e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,9 @@ CPACK_COMPONENT("volk_devel" add_subdirectory(volk) endif(ENABLE_VOLK) +# Handle gr_log enable/disable +GR_LOGGING() + ######################################################################## # Distribute the README file ######################################################################## diff --git a/cmake/Modules/FindLog4cxx.cmake b/cmake/Modules/FindLog4cxx.cmake new file mode 100644 index 0000000000..b1e4f6f1f7 --- /dev/null +++ b/cmake/Modules/FindLog4cxx.cmake @@ -0,0 +1,28 @@ +# CMake module to find LOG4CXX library + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(PC_LOG4CXX liblog4cxx) + +FIND_PATH( + LOG4CXX_INCLUDE_DIRS + NAMES log4cxx/log4cxx.h + HINTS $ENV{LOG4CXX_DIR}/include + ${PC_LOG4CXX_INCLUDE_DIRS} + PATHS /usr/local/include + /usr/include +) + +FIND_LIBRARY( + LOG4CXX_LIBRARIES + NAMES log4cxx + HINTS $ENV{LOG4CXX_DIR}/lib + ${PC_LOG4CXX_LIBRARIES} + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LOG4CXX DEFAULT_MSG LOG4CXX_LIBRARIES LOG4CXX_INCLUDE_DIRS) +MARK_AS_ADVANCED(LOG4CXX_LIBRARIES LOG4CXX_INCLUDE_DIRS) diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake index a73e3e6d7e..adf64ab97b 100644 --- a/cmake/Modules/GrMiscUtils.cmake +++ b/cmake/Modules/GrMiscUtils.cmake @@ -208,3 +208,36 @@ function(GR_GEN_TARGET_DEPS name var) set(${var} "DEPENDS;${name};COMMAND;${name}" PARENT_SCOPE) endif() endfunction(GR_GEN_TARGET_DEPS) + +######################################################################## +# Control use of gr_log +# Usage: +# GR_LOGGING() +# +# Will set ENABLE_GR_LOG to 1 by default. +# Can manually set with -DENABLE_GR_LOG=0|1 +######################################################################## +function(GR_LOGGING) + find_package(Log4cxx) + + OPTION(ENABLE_GR_LOG "Use gr_log" ON) + + if(NOT LOG4CXX_FOUND) + SET(ENABLE_GR_LOG OFF) + endif(NOT LOG4CXX_FOUND) + + message(STATUS "ENABLE_GR_LOG set to ${ENABLE_GR_LOG}.") + + SET(ENABLE_GR_LOG ${ENABLE_GR_LOG} CACHE INTERNAL "" FORCE) + + if(ENABLE_GR_LOG) + add_definitions( -DENABLE_GR_LOG ) + else(ENABLE_GR_LOG) + # If not enabled or available, set these variable to + # blank so we can use them later without having to + # check ENABLE_GR_LOG each time. + SET(LOG4CXX_INCLUDE_DIRS "" CACHE INTERNAL "" FORCE) + SET(LOG4CXX_LIBRARY_DIRS "" CACHE INTERNAL "" FORCE) + SET(LOG4CXX_LIBRARIES "" CACHE INTERNAL "" FORCE) + endif(ENABLE_GR_LOG) +endfunction(GR_LOGGING) diff --git a/docs/doxygen/other/main_page.dox b/docs/doxygen/other/main_page.dox index 8f69a97373..c5d5a44cb7 100644 --- a/docs/doxygen/other/main_page.dox +++ b/docs/doxygen/other/main_page.dox @@ -48,4 +48,116 @@ Many blocks have already been converted to use Volk in their calls, so they can also serve as examples. See the gr_complex_to_xxx.h file for examples of various blocks that make use of Volk. + +\section logging Logging + +GNU Radio has a logging interface to enable various levels of logging +information to be printed to the console or a file. The logger derives +from log4cxx (http://logging.apache.org/log4cxx) which is readily +available in most Linux distributions. This is an optional dependency +and GNU Radio will work without it. + +When configuring GNU Radio, the -DENABLE_GR_LOG=On|Off option to cmake +will allow the user to toggle use of the logger on and off and will +turn off if log4cxx is not available. + +Logging is useful for blocks to print out certain amounts of data at +different levels. These levels are: + + TRACE < DEBUG < INFO < WARN < ERROR < FATAL + +The order here determines the level of output. When using the Debug +level, for instance, all Debug and higher messages are logged and +Trace is ignored. + +\subsection use_logging Using the Logging Features + +In a GNU Radio block, you use the logging features by calling macros +that are defined in gr_log.h, which must be included for use. + +The logger must be properly configured, which is easiest by defining a +configuration file. The log4cxx website will provide more information +on how configuration works and looks. Mostly, a default configuration +script provided with GNU Radio can be used. After installation, the +default configuration script is located at: + + $prefix/etc/gnuradio/gr_log_default.xml + +However, we use the global GNU Radio configuration file to tell the +system where this file is located. In the [LOG] section of the +configuration file, the location of the logger's XML file can be +specified. The default configuration file is found in: + + $prefix/etc/gnuradio/conf.d/gnuradio-core.conf + +A local "~/.gnuradio/config.conf" file can be used to override any +parameter in the global file. + +For the following examples, we will assume that our local +"~/.gnuradio/config.conf" looks like this: + +\code +[LOG] +log_file = /opt/gr/etc/gnuadio/gr_log_default.xml +log_level = All +\endcode + +The startup and configuration process proceeds as follows. + +\code + 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, <name>); + GR_LOG_SET_LEVEL(LOG, log_level); +\endcode + +The default config file has two names that can be used (as std::string +types): "gr_log" and "gr_log_debug". The first one will print +all levels of logging informaiton while the second one will only print +Debug and above. + +Names of loggers are global, so "gr_log" as a name will be the same +logger no matter where it is picked from. + +The "LOG" name for the logger is now a LoggerPtr object and can be +named anything. + +For a given block, it is recommended that a new name be specified for +individual control over the logger as loggers are globally held in a +LoggerManager. Since log4cxx is hierarchical, a new name is created by +appending a string to an existing logger. So a general logger used in +the digital_costas_loop_cc.cc class, for instance, could look +something like "gr_log.costas_loop". This will inherit all properties +of the parent logger, "gr_log". + +After calling "GR_LOG_GETLOGGER", the LoggerPtr that was specified, +"LOG" in the example above, is used to set the properties. The main +setting we are generally interested in is the level of the +logger. This will determine if this logger gets outputted or not. In +this case, we are actually getting the gr_log level from the GNU Radio +configuration file, stored in log_level. The macro GR_LOG_SET_LEVEL +can take either a string or a log4cxx::LevelPtr object. The log_level +variable in this case holds a string read in from the config file, and +it's case insensitive. I can be "off", "all", "trace", "debug", +"info", "warn", "error", or "fatal" to match with the levels above. + +In our example here, all logging information is displayed because the +config file specifies "All". We can then easily turn off all reporting +by setting this value to "Off". + +The various logging macros are defined in gr_log.h. Here are some +simple exmaples of using them: + +\code + GR_LOG_TRACE(LOG, "TRACE message"); + GR_LOG_DEBUG(LOG, "DEBUG message"); + GR_LOG_INFO(LOG, "INFO message"); + GR_LOG_WARN(LOG, "WARNING message"); + GR_LOG_ERROR(LOG, "ERROR message"); + GR_FATAL(LOG, "FATAL message"); + GR_ERRORIF(LOG, a>b, "CONDITIONAL ERROR message"); + GR_ASSERT(LOG, a>b, "ASSERT error message"); +\endcode + */ diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt index 4e76b3c5a6..aed16c563d 100644 --- a/gnuradio-core/CMakeLists.txt +++ b/gnuradio-core/CMakeLists.txt @@ -108,12 +108,26 @@ CPACK_COMPONENT("core_swig" DEPENDS "gruel_swig;core_python;core_devel" ) +# Setup configure file +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio-core.conf.in + ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-core.conf +@ONLY) + install( FILES gnuradio-core.conf DESTINATION ${GR_PREFSDIR} COMPONENT "core_runtime" ) +if(ENABLE_GR_LOG) +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/gr_log_default.xml + DESTINATION ${GR_CONF_DIR}/gnuradio + COMPONENT "core_runtime" +) +endif(ENABLE_GR_LOG) + ######################################################################## # Add subdirectories ######################################################################## diff --git a/gnuradio-core/gnuradio-core.conf b/gnuradio-core/gnuradio-core.conf.in index 178b288e8d..dad07cd245 100644 --- a/gnuradio-core/gnuradio-core.conf +++ b/gnuradio-core/gnuradio-core.conf.in @@ -5,3 +5,10 @@ [DEFAULT] verbose = False + + +[LOG] + +log_config = @CMAKE_INSTALL_PREFIX@/etc/gnuradio/gr_log_default.xml +log_level = all +debug_level = DEBUG diff --git a/gnuradio-core/gr_log_default.xml b/gnuradio-core/gr_log_default.xml new file mode 100644 index 0000000000..be721bb021 --- /dev/null +++ b/gnuradio-core/gr_log_default.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + * Copyright 2006,2010,2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +--> + + <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + + <appender name="RootConsoleAppender" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="Root :%-5p %c{1} - %m%n"/> + </layout> + </appender> + + <!--Add appender to root to log ALL msgs in one place--> + <root> + <priority value="all" /> + </root> + + <appender name="errLogRootConsoleAppender" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="errLoggerRoot :%-5p %c{1} - %m%n"/> + </layout> + </appender> + + <!-- Specify the level for some specific loggers--> + <category name="gr_log" > + <priority value ="all" /> + <appender-ref ref="errLogRootConsoleAppender"/> + </category> + + <appender name="errConsoleAppender" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="err :%-5p %c{1} - %m%n"/> + </layout> + </appender> + + <category name="gr_log_debug" > + <priority value ="DEBUG" /> + <appender-ref ref="errConsoleAppender"/> + </category> + + </log4j:configuration> + diff --git a/gnuradio-core/src/lib/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 diff --git a/gnuradio-core/src/tests/CMakeLists.txt b/gnuradio-core/src/tests/CMakeLists.txt index 3c7f632b37..616b192b6a 100644 --- a/gnuradio-core/src/tests/CMakeLists.txt +++ b/gnuradio-core/src/tests/CMakeLists.txt @@ -33,6 +33,9 @@ link_directories(${Boost_LIBRARY_DIRS}) include_directories(${CPPUNIT_INCLUDE_DIRS}) link_directories(${CPPUNIT_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Build benchmarks and non-registered tests ######################################################################## diff --git a/gr-atsc/src/lib/CMakeLists.txt b/gr-atsc/src/lib/CMakeLists.txt index 39dbefa60f..9cec0ab1b5 100644 --- a/gr-atsc/src/lib/CMakeLists.txt +++ b/gr-atsc/src/lib/CMakeLists.txt @@ -29,6 +29,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Generate viterbi mux source # http://www.vtk.org/Wiki/CMake_Cross_Compiling#Using_executables_in_the_build_created_during_the_build @@ -97,6 +100,7 @@ list(APPEND gr_atsc_sources list(APPEND atsc_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-atsc SHARED ${gr_atsc_sources}) diff --git a/gr-audio/lib/CMakeLists.txt b/gr-audio/lib/CMakeLists.txt index c1781af79e..a42ee63308 100644 --- a/gr-audio/lib/CMakeLists.txt +++ b/gr-audio/lib/CMakeLists.txt @@ -29,7 +29,10 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) -list(APPEND gr_audio_libs gnuradio-core ${Boost_LIBRARIES}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + +list(APPEND gr_audio_libs gnuradio-core ${Boost_LIBRARIES} ${LOG4CXX_LIBRARIES}) list(APPEND gr_audio_sources gr_audio_registry.cc) list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/gr-audio.conf) diff --git a/gr-comedi/src/CMakeLists.txt b/gr-comedi/src/CMakeLists.txt index 5291e4d905..09c940ab9e 100644 --- a/gr-comedi/src/CMakeLists.txt +++ b/gr-comedi/src/CMakeLists.txt @@ -31,6 +31,9 @@ link_directories(${Boost_LIBRARY_DIRS}) include_directories(${COMEDI_INCLUDE_DIRS}) link_directories(${COMEDI_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -44,6 +47,7 @@ list(APPEND comedi_libs gnuradio-core ${Boost_LIBRARIES} ${COMEDI_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-comedi SHARED ${gr_comedi_sources}) diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt index bd4f1a5004..6c2aba941d 100644 --- a/gr-digital/lib/CMakeLists.txt +++ b/gr-digital/lib/CMakeLists.txt @@ -29,6 +29,8 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) ######################################################################## # generate helper scripts to expand templated files @@ -85,10 +87,12 @@ endmacro(expand_cc) # Invoke macro to generate various sources ######################################################################## expand_cc(digital_chunks_to_symbols_XX bf bc sf sc if ic) +>>>>>>> master ######################################################################## # Setup library ######################################################################## + list(APPEND gr_digital_sources ${generated_sources} digital_impl_glfsr.cc @@ -140,6 +144,7 @@ list(APPEND gr_digital_sources list(APPEND digital_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-digital SHARED ${gr_digital_sources}) diff --git a/gr-fcd/lib/CMakeLists.txt b/gr-fcd/lib/CMakeLists.txt index 9a5605d99c..e7ed6d8d79 100644 --- a/gr-fcd/lib/CMakeLists.txt +++ b/gr-fcd/lib/CMakeLists.txt @@ -35,6 +35,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -66,7 +69,7 @@ add_library(gnuradio-fcd SHARED ${gr_fcd_sources}) if (LINUX) list(APPEND fcd_libs rt) endif() -target_link_libraries(gnuradio-fcd ${fcd_libs}) +target_link_libraries(gnuradio-fcd ${fcd_libs} ${LOG4CXX_LIBRARIES}) GR_LIBRARY_FOO(gnuradio-fcd RUNTIME_COMPONENT "fcd_runtime" DEVEL_COMPONENT "fcd_devel") diff --git a/gr-howto-write-a-block/CMakeLists.txt b/gr-howto-write-a-block/CMakeLists.txt index 5d2477f893..8877ccb0ff 100644 --- a/gr-howto-write-a-block/CMakeLists.txt +++ b/gr-howto-write-a-block/CMakeLists.txt @@ -94,18 +94,24 @@ if(NOT GNURADIO_CORE_FOUND) message(FATAL_ERROR "GnuRadio Core required to compile howto") endif() +# Handle gr_log enable/disable +include(GrMiscUtils) #define LIB_SUFFIX +GR_LOGGING() + ######################################################################## # Setup the include and linker paths ######################################################################## include_directories( ${CMAKE_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS} + ${LOG4CXX_INCLUDE_DIRS} ${GRUEL_INCLUDE_DIRS} ${GNURADIO_CORE_INCLUDE_DIRS} ) link_directories( ${Boost_LIBRARY_DIRS} + ${LOG4CXX_LIBRARY_DIRS} ${GRUEL_LIBRARY_DIRS} ${GNURADIO_CORE_LIBRARY_DIRS} ) diff --git a/gr-howto-write-a-block/cmake/Modules/FindLog4cxx.cmake b/gr-howto-write-a-block/cmake/Modules/FindLog4cxx.cmake new file mode 100644 index 0000000000..b1e4f6f1f7 --- /dev/null +++ b/gr-howto-write-a-block/cmake/Modules/FindLog4cxx.cmake @@ -0,0 +1,28 @@ +# CMake module to find LOG4CXX library + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(PC_LOG4CXX liblog4cxx) + +FIND_PATH( + LOG4CXX_INCLUDE_DIRS + NAMES log4cxx/log4cxx.h + HINTS $ENV{LOG4CXX_DIR}/include + ${PC_LOG4CXX_INCLUDE_DIRS} + PATHS /usr/local/include + /usr/include +) + +FIND_LIBRARY( + LOG4CXX_LIBRARIES + NAMES log4cxx + HINTS $ENV{LOG4CXX_DIR}/lib + ${PC_LOG4CXX_LIBRARIES} + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LOG4CXX DEFAULT_MSG LOG4CXX_LIBRARIES LOG4CXX_INCLUDE_DIRS) +MARK_AS_ADVANCED(LOG4CXX_LIBRARIES LOG4CXX_INCLUDE_DIRS) diff --git a/gr-howto-write-a-block/cmake/Modules/GrMiscUtils.cmake b/gr-howto-write-a-block/cmake/Modules/GrMiscUtils.cmake index 9331d5debc..cffe2f6540 100644 --- a/gr-howto-write-a-block/cmake/Modules/GrMiscUtils.cmake +++ b/gr-howto-write-a-block/cmake/Modules/GrMiscUtils.cmake @@ -208,3 +208,35 @@ function(GR_GEN_TARGET_DEPS name var) set(${var} "DEPENDS;${name};COMMAND;${name}" PARENT_SCOPE) endif() endfunction(GR_GEN_TARGET_DEPS) + + +######################################################################## +# Control use of gr_log +# Usage: +# GR_LOGGING() +# +# Will set ENABLE_GR_LOG to 1 by default. +# Can manually set with -DENABLE_GR_LOG=0|1 +######################################################################## +function(GR_LOGGING) + find_package(Log4cxx) + + OPTION(ENABLE_GR_LOG "Use gr_log" ON) + + if(NOT LOG4CXX_FOUND) + SET(ENABLE_GR_LOG OFF) + endif(NOT LOG4CXX_FOUND) + + message(STATUS "ENABLE_GR_LOG set to ${ENABLE_GR_LOG}.") + + if(ENABLE_GR_LOG) + add_definitions( -DENABLE_GR_LOG ) + else(ENABLE_GR_LOG) + # If not enabled or available, set these variable to + # blank so we can use them later without having to + # check ENABLE_GR_LOG each time. + SET(LOG4CXX_INCLUDE_DIRS "" CACHE INTERNAL "" FORCE) + SET(LOG4CXX_LIBRARY_DIRS "" CACHE INTERNAL "" FORCE) + SET(LOG4CXX_LIBRARIES "" CACHE INTERNAL "" FORCE) + endif(ENABLE_GR_LOG) +endfunction(GR_LOGGING) diff --git a/gr-howto-write-a-block/lib/CMakeLists.txt b/gr-howto-write-a-block/lib/CMakeLists.txt index 835ae02d60..a55bb1fa4a 100644 --- a/gr-howto-write-a-block/lib/CMakeLists.txt +++ b/gr-howto-write-a-block/lib/CMakeLists.txt @@ -23,7 +23,11 @@ include(GrPlatform) #define LIB_SUFFIX add_library(gnuradio-howto SHARED howto_square_ff.cc howto_square2_ff.cc) -target_link_libraries(gnuradio-howto ${Boost_LIBRARIES} ${GRUEL_LIBRARIES} ${GNURADIO_CORE_LIBRARIES}) +target_link_libraries(gnuradio-howto + ${Boost_LIBRARIES} + ${GRUEL_LIBRARIES} + ${GNURADIO_CORE_LIBRARIES} + ${LOG4CXX_LIBRARIES}) set_target_properties(gnuradio-howto PROPERTIES DEFINE_SYMBOL "gnuradio_howto_EXPORTS") ######################################################################## diff --git a/gr-noaa/lib/CMakeLists.txt b/gr-noaa/lib/CMakeLists.txt index 7bac21e4a4..7a9b71d84f 100644 --- a/gr-noaa/lib/CMakeLists.txt +++ b/gr-noaa/lib/CMakeLists.txt @@ -28,6 +28,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -40,6 +43,7 @@ list(APPEND gr_noaa_sources list(APPEND noaa_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-noaa SHARED ${gr_noaa_sources}) diff --git a/gr-pager/lib/CMakeLists.txt b/gr-pager/lib/CMakeLists.txt index 7b91c5a33b..dfde704ee8 100644 --- a/gr-pager/lib/CMakeLists.txt +++ b/gr-pager/lib/CMakeLists.txt @@ -28,6 +28,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -45,6 +48,7 @@ list(APPEND gr_pager_sources list(APPEND pager_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-pager SHARED ${gr_pager_sources}) diff --git a/gr-qtgui/lib/CMakeLists.txt b/gr-qtgui/lib/CMakeLists.txt index 2dc35e81cb..6a8016df0f 100644 --- a/gr-qtgui/lib/CMakeLists.txt +++ b/gr-qtgui/lib/CMakeLists.txt @@ -69,6 +69,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + include_directories(${QWT_INCLUDE_DIRS}) link_directories(${QWT_LIBRARY_DIRS}) @@ -83,6 +86,7 @@ list(APPEND qtgui_libs ${QT_LIBRARIES} ${QWT_LIBRARIES} ${PYTHON_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_definitions(-DQWT_DLL) #setup QWT library linkage diff --git a/gr-shd/lib/CMakeLists.txt b/gr-shd/lib/CMakeLists.txt index 9ddf109af0..41f6b60ae4 100644 --- a/gr-shd/lib/CMakeLists.txt +++ b/gr-shd/lib/CMakeLists.txt @@ -31,6 +31,9 @@ link_directories(${SHD_LIBRARY_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -43,6 +46,7 @@ list(APPEND shd_libs gnuradio-core ${Boost_LIBRARIES} ${SHD_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-shd SHARED ${gr_shd_sources}) diff --git a/gr-trellis/src/lib/CMakeLists.txt b/gr-trellis/src/lib/CMakeLists.txt index 8f29f9605b..be7baa785d 100644 --- a/gr-trellis/src/lib/CMakeLists.txt +++ b/gr-trellis/src/lib/CMakeLists.txt @@ -31,6 +31,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # generate the python helper script which calls into the build utils ######################################################################## @@ -149,6 +152,7 @@ list(APPEND gr_trellis_sources list(APPEND trellis_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-trellis SHARED ${gr_trellis_sources}) diff --git a/gr-uhd/lib/CMakeLists.txt b/gr-uhd/lib/CMakeLists.txt index 810d1446ac..703e4e9460 100644 --- a/gr-uhd/lib/CMakeLists.txt +++ b/gr-uhd/lib/CMakeLists.txt @@ -32,6 +32,9 @@ link_directories(${UHD_LIBRARY_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -45,6 +48,7 @@ list(APPEND uhd_libs gnuradio-core ${Boost_LIBRARIES} ${UHD_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-uhd SHARED ${gr_uhd_sources}) diff --git a/gr-video-sdl/src/CMakeLists.txt b/gr-video-sdl/src/CMakeLists.txt index a5c5b8cbd2..d423459e6e 100644 --- a/gr-video-sdl/src/CMakeLists.txt +++ b/gr-video-sdl/src/CMakeLists.txt @@ -28,6 +28,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + include_directories(${SDL_INCLUDE_DIR}) ######################################################################## @@ -42,6 +45,7 @@ list(APPEND video_sdl_libs gnuradio-core ${Boost_LIBRARIES} ${SDL_LIBRARY} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-video-sdl SHARED ${gr_video_sdl_sources}) diff --git a/gr-vocoder/lib/CMakeLists.txt b/gr-vocoder/lib/CMakeLists.txt index 69219b03f5..67d06d4b29 100644 --- a/gr-vocoder/lib/CMakeLists.txt +++ b/gr-vocoder/lib/CMakeLists.txt @@ -28,6 +28,9 @@ include_directories( include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -60,6 +63,7 @@ GR_INCLUDE_SUBDIRECTORY(gsm) list(APPEND vocoder_libs gnuradio-core ${Boost_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-vocoder SHARED ${gr_vocoder_sources}) diff --git a/gr-wavelet/lib/CMakeLists.txt b/gr-wavelet/lib/CMakeLists.txt index 9594f6a6ac..b97446db9d 100644 --- a/gr-wavelet/lib/CMakeLists.txt +++ b/gr-wavelet/lib/CMakeLists.txt @@ -34,6 +34,9 @@ link_directories(${Boost_LIBRARY_DIRS}) link_directories(${GSL_LIBRARY_DIRS}) add_definitions(${GSL_DEFINITIONS}) +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + ######################################################################## # Setup library ######################################################################## @@ -48,6 +51,7 @@ list(APPEND wavelet_libs ${Boost_LIBRARIES} ${WAVELET_LIBRARIES} ${GSL_LIBRARIES} + ${LOG4CXX_LIBRARIES} ) add_library(gnuradio-wavelet SHARED ${gr_wavelet_sources}) |