summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2012-06-07 09:36:26 -0400
committerTom Rondeau <trondeau@vt.edu>2012-06-07 12:44:52 -0400
commit7cfe8af854348924d31aa1feb5978da6dd1fe1c4 (patch)
tree97191856f13febd0b31df5fa8808018537ce854b /gnuradio-core/src
parentb40ccb1d3f12a6837df235ccbceee5180c711efa (diff)
core: Adds a gr-log concept for easy logging at various levels.
Uses log4cxx and is optional. Macro based and macros are simple pass-throughs if this dependency does not exist or if the gr-log is disabled.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/CMakeLists.txt17
-rw-r--r--gnuradio-core/src/lib/runtime/CMakeLists.txt13
-rw-r--r--gnuradio-core/src/lib/runtime/gr_log.cc41
-rw-r--r--gnuradio-core/src/lib/runtime/gr_log.h266
-rw-r--r--gnuradio-core/src/lib/runtime/gr_log.i85
-rw-r--r--gnuradio-core/src/lib/runtime/gr_log_default.xml64
-rw-r--r--gnuradio-core/src/lib/runtime/qa_gr_log.cc51
-rw-r--r--gnuradio-core/src/lib/runtime/qa_gr_log.h42
-rw-r--r--gnuradio-core/src/lib/runtime/qa_runtime.cc2
-rw-r--r--gnuradio-core/src/lib/runtime/runtime.i2
-rw-r--r--gnuradio-core/src/lib/swig/CMakeLists.txt11
-rw-r--r--gnuradio-core/src/tests/CMakeLists.txt6
12 files changed, 600 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/CMakeLists.txt b/gnuradio-core/src/lib/CMakeLists.txt
index 9c980157db..4412558628 100644
--- a/gnuradio-core/src/lib/CMakeLists.txt
+++ b/gnuradio-core/src/lib/CMakeLists.txt
@@ -50,9 +50,22 @@ link_directories(${Boost_LIBRARY_DIRS})
include_directories(${FFTW3F_INCLUDE_DIRS})
link_directories(${FFTW3F_LIBRARY_DIRS})
+
########################################################################
# Setup library
########################################################################
+
+# Only use if log4cxx is installed
+# Define DISABLE_GR_LOG so .h and .cc files can turn actual
+# logging and insert dummy functions.
+if(LOG4CXX_FOUND)
+ include_directories(${LOG4CXX_INCLUDE_DIRS})
+ link_directories(${LOG4CXX_LIBRARIES})
+ list(APPEND gnuradio_core_libs ${LOG4CXX_LIBRARIES} )
+else(LOG4CXX_FOUND)
+ add_definitions(-DDISABLE_GR_LOG)
+endif(LOG4CXX_FOUND)
+
list(APPEND gnuradio_core_libs
gruel
${Boost_LIBRARIES}
@@ -99,4 +112,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/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt
index 1415ff4c6c..e36e83e84f 100644
--- a/gnuradio-core/src/lib/runtime/CMakeLists.txt
+++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt
@@ -38,6 +38,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
@@ -81,6 +82,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
)
########################################################################
@@ -101,6 +103,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
@@ -145,6 +148,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
@@ -159,4 +163,13 @@ install(FILES
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
COMPONENT "core_swig"
)
+
endif(ENABLE_PYTHON)
+
+if(ENABLE_GR_LOG)
+install(FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_log_default.xml
+ DESTINATION ${GR_PKG_DATA_DIR}
+ COMPONENT "core_runtime"
+)
+endif(ENABLE_GR_LOG)
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..5478bd70c0
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_log.cc
@@ -0,0 +1,41 @@
+/* -*- 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>
+
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..1a52d2aef6
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_log.h
@@ -0,0 +1,266 @@
+/* -*- 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)
+*
+*/
+
+//If DISABLE_GR_LOG set then clear all logging macros
+#ifdef DISABLE_GR_LOG
+
+#define GR_CONFIG_LOGGER(config)
+#define GR_LOG_GETLOGGER(logger, name)
+#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)
+
+#else
+
+#include <stdio.h>
+#include <string>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <log4cxx/logger.h>
+#include <log4cxx/logmanager.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);
+
+/* 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);}
+
+
+// Load configuration file
+void
+logger_load_config(std::string config_filename)
+{
+ if(config_filename.find(".xml") != std::string::npos) {
+ DOMConfigurator::configure(config_filename);
+ }
+ else {
+ PropertyConfigurator::configure(config_filename);
+ }
+}
+
+/*!
+ * \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)
+ {
+ if(LogManager::exists(name)) {
+ LoggerPtr logger = Logger::getLogger(name);
+ return logger;
+ }
+ else {
+ LoggerPtr logger = Logger::getLogger(name);
+ logger->setLevel(log4cxx::Level::getOff());
+ return logger;
+ }
+ };
+
+ // 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 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);};
+};
+
+#endif /* DISABLE_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..d56edd4f37
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_log.i
@@ -0,0 +1,85 @@
+/* -*- 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>
+%}
+
+//-----------------------------------
+
+
+#ifndef DISABLE_GR_LOG
+
+%{
+// The .h files
+#include <gr_log.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/logmanager.h>
+%}
+
+class LoggerPtr {
+public:
+ ~LoggerPtr();
+};
+
+class gr_log
+{
+private:
+
+public:
+// gr_log(std::string config_filename);
+ gr_log(std::string config_filename,int watchPeriodSec);
+ 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 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
diff --git a/gnuradio-core/src/lib/runtime/gr_log_default.xml b/gnuradio-core/src/lib/runtime/gr_log_default.xml
new file mode 100644
index 0000000000..be721bb021
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/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/runtime/qa_gr_log.cc b/gnuradio-core/src/lib/runtime/qa_gr_log.cc
new file mode 100644
index 0000000000..d8d0914992
--- /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()
+{
+#ifndef DISABLE_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 d3c381b4bc..3bef440f66 100644
--- a/gnuradio-core/src/lib/swig/CMakeLists.txt
+++ b/gnuradio-core/src/lib/swig/CMakeLists.txt
@@ -33,6 +33,16 @@ set(GR_SWIG_INCLUDE_DIRS
)
set(GR_SWIG_LIBRARIES gnuradio-core)
+# Only use if log4cxx is installed
+# Define DISABLE_GR_LOG for the .i file to ignore it.
+if(LOG4CXX_FOUND)
+ link_directories(${LOG4CXX_LIBRARY_DIRS})
+ list(APPEND GR_SWIG_LIBRARIES log4cxx)
+ list(APPEND GR_SWIG_INCLUDE_DIRS ${LOG4CXX_INCLUDE_DIRS})
+else(LOG4CXX_FOUND)
+ add_definitions(-DDISABLE_GR_LOG)
+endif(LOG4CXX_FOUND)
+
########################################################################
# Build and install the swig targets
########################################################################
@@ -46,6 +56,7 @@ set(GR_SWIG_LIBRARIES gnuradio-core)
set(GR_SWIG_TARGET_DEPS gengen_generated filter_generated)
foreach(what runtime general gengen filter io hier)
+ SET(GR_SWIG_FLAGS "-DDISABLE_GR_LOG")
SET(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/${what}_swig_doc.i)
SET(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../${what} ${CMAKE_CURRENT_BINARY_DIR}/../${what})
GR_SWIG_MAKE(gnuradio_core_${what} gnuradio_core_${what}.i)
diff --git a/gnuradio-core/src/tests/CMakeLists.txt b/gnuradio-core/src/tests/CMakeLists.txt
index 3c7f632b37..6a18dc38a9 100644
--- a/gnuradio-core/src/tests/CMakeLists.txt
+++ b/gnuradio-core/src/tests/CMakeLists.txt
@@ -33,6 +33,12 @@ link_directories(${Boost_LIBRARY_DIRS})
include_directories(${CPPUNIT_INCLUDE_DIRS})
link_directories(${CPPUNIT_LIBRARY_DIRS})
+# Only use if log4cxx is installed
+if(LOG4CXX_FOUND)
+ include_directories(${LOG4CXX_INCLUDE_DIRS})
+ link_directories(${LOG4CXX_LIBRARY_DIRS})
+endif(LOG4CXX_FOUND)
+
########################################################################
# Build benchmarks and non-registered tests
########################################################################