GNU Radio 3.7.1 C++ API
logger.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2012-2013 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 /*******************************************************************************
00024 * Author: Mark Plett
00025 * Description:
00026 *   The gr::logger module wraps the log4cpp library for logging in gnuradio
00027 *******************************************************************************/
00028 
00029 #ifndef INCLUDED_GR_LOGGER_H
00030 #define INCLUDED_GR_LOGGER_H
00031 
00032 /*!
00033 * \ingroup logging
00034 * \brief GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
00035 *
00036 */
00037 
00038 #ifndef ENABLE_GR_LOG
00039 #define ENABLE_GR_LOG
00040 #endif
00041 #ifndef HAVE_LOG4CPP
00042 #define HAVE_LOG4CPP
00043 #endif
00044 
00045 #ifdef _MSC_VER
00046 typedef unsigned short mode_t;
00047 #endif
00048 
00049 #include <gnuradio/api.h>
00050 #include <assert.h>
00051 #include <iostream>
00052 #include <time.h>
00053 #include <boost/filesystem.hpp>
00054 #include <boost/thread.hpp>
00055 #include <boost/format.hpp>
00056 #include <pmt/pmt.h>
00057 
00058 #ifdef ENABLE_GR_LOG
00059 
00060 // We have three configurations... first logging to stdout/stderr
00061 #ifndef HAVE_LOG4CPP
00062 
00063 namespace gr {
00064   //#warning GR logging Enabled and using std::cout
00065   typedef std::string logger_ptr;
00066 } /* namespace gr */
00067 
00068 #define GR_LOG_DECLARE_LOGPTR(logger)
00069 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
00070 #define GR_CONFIG_LOGGER(config)
00071 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
00072 #define GR_LOG_GETLOGGER(logger, name) 
00073 #define GR_SET_LEVEL(name, level)
00074 #define GR_LOG_SET_LEVEL(logger, level) 
00075 #define GR_GET_LEVEL(name, level)
00076 #define GR_LOG_GET_LEVEL(logger, level)
00077 #define GR_ADD_APPENDER(name,appender)
00078 #define GR_LOG_ADD_APPENDER(logger,appender)
00079 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
00080 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
00081 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
00082 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
00083 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
00084 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
00085 #define GR_GET_LOGGER_NAMES(names)
00086 #define GR_RESET_CONFIGURATION()
00087 #define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
00088 #define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
00089 #define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
00090 #define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
00091 #define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
00092 #define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
00093 #define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
00094 #define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
00095 #define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
00096 #define GR_ERRORIF(name, cond, msg) {if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
00097 #define GR_ASSERT(name, cond, msg) {if(!(cond)) std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);}
00098 #define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
00099 #define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
00100 #define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
00101 #define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
00102 #define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
00103 #define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
00104 #define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
00105 #define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
00106 #define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
00107 #define GR_LOG_ERRORIF(logger, cond, msg) {             \
00108     if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl;}
00109 #define GR_LOG_ASSERT(logger, cond, msg) {                              \
00110     if(!(cond)) {std::cerr<<"FATAL: "<<msg<<std::endl; assert(cond);};}
00111 
00112 
00113 #else /* HAVE_LOG4CPP */
00114 
00115 // Second configuration...logging to log4cpp
00116 #include <log4cpp/Category.hh>
00117 #include <log4cpp/PropertyConfigurator.hh>
00118 #include <log4cpp/FileAppender.hh>
00119 #include <log4cpp/RollingFileAppender.hh>
00120 #include <log4cpp/OstreamAppender.hh>
00121 #include <log4cpp/PatternLayout.hh>
00122 
00123 namespace gr {
00124 
00125   /*!
00126    * \brief GR_LOG macros
00127    * \ingroup logging
00128    *
00129    * These macros wrap the standard LOG4CPP_LEVEL macros.  The availablie macros
00130    * are:
00131    *  LOG_DEBUG
00132    *  LOG_INFO
00133    *  LOG_WARN
00134    *  LOG_TRACE
00135    *  LOG_ERROR
00136    *  LOG_ALERT
00137    *  LOG_CRIT
00138    *  LOG_FATAL
00139    *  LOG_EMERG
00140    */
00141   typedef log4cpp::Category* logger_ptr;
00142 
00143 } /* namespace gr */
00144 
00145 
00146   /* Macros for Programmatic Configuration */
00147 #define GR_LOG_DECLARE_LOGPTR(logger)           \
00148   gr::logger_ptr logger;
00149 
00150 #define GR_LOG_ASSIGN_LOGPTR(logger,name)       \
00151   logger = gr::logger_get_logger(name);
00152 
00153 #define GR_CONFIG_LOGGER(config)                \
00154   gr::logger_config::load_config(config)
00155 
00156 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)       \
00157   gr::logger_config::load_config(config,period)
00158 
00159 #define GR_LOG_GETLOGGER(logger, name)                  \
00160   gr::logger_ptr logger = gr::logger_get_logger(name);
00161 
00162 #define GR_SET_LEVEL(name, level) {                             \
00163     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00164     gr::logger_set_level(logger,level);}
00165 
00166 #define GR_LOG_SET_LEVEL(logger, level)         \
00167   gr::logger_set_level(logger, level);
00168 
00169 #define GR_GET_LEVEL(name, level) {                             \
00170     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00171     gr::logger_get_level(logger,level);}
00172 
00173 #define GR_LOG_GET_LEVEL(logger, level)         \
00174   gr::logger_get_level(logger,level);
00175 
00176 #define GR_ADD_APPENDER(name, appender) {                       \
00177     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00178     gr::logger_add_appender(logger,appender);}
00179 
00180 #define GR_LOG_ADD_APPENDER(logger, appender) { \
00181     gr::logger_add_appender(logger, appender);}
00182 
00183 #define GR_ADD_CONSOLE_APPENDER(name, target, pattern) {        \
00184     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00185     gr::logger_add_console_appender(logger,target,pattern);}
00186 
00187 #define GR_LOG_ADD_CONSOLE_APPENDER(logger, target, pattern) {  \
00188     gr::logger_add_console_appender(logger,target,pattern);}
00189 
00190 #define GR_ADD_FILE_APPENDER(name, filename, append, pattern) {         \
00191     gr::logger_ptr logger = gr::logger_get_logger(name);                \
00192     gr::logger_add_file_appender(logger,filename,append,pattern);}
00193 
00194 #define GR_LOG_ADD_FILE_APPENDER(logger, filename, append, pattern) {   \
00195     gr::logger_add_file_appender(logger,filename,append,pattern);}
00196 
00197 #define GR_ADD_ROLLINGFILE_APPENDER(name, filename, filesize, bkup_index, append, mode, pattern) { \
00198     gr::logger_ptr logger = gr::logger_get_logger(name);                    \
00199     gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
00200 
00201 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger, filename, filesize, bkup_index, append, mode, pattern) { \
00202     gr::logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
00203 
00204 #define GR_GET_LOGGER_NAMES(names) {            \
00205     names = gr::logger_get_logger_names();}
00206 
00207 #define GR_RESET_CONFIGURATION()                \
00208     gr::logger_config::reset_config();
00209 
00210   /* Logger name referenced macros */
00211 #define GR_DEBUG(name, msg) {                                   \
00212     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00213     *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
00214 
00215 #define GR_INFO(name, msg) {                                    \
00216     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00217     *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
00218 
00219 #define GR_NOTICE(name, msg) {                                  \
00220     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00221     *logger << log4cpp::Priority::NOTICE << msg;}
00222 
00223 #define GR_WARN(name, msg) {                                    \
00224     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00225     *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
00226 
00227 #define GR_ERROR(name, msg) {                                   \
00228     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00229     *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
00230 
00231 #define GR_CRIT(name, msg) {                                    \
00232     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00233     *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
00234 
00235 #define GR_ALERT(name, msg) {                                   \
00236     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00237     *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
00238 
00239 #define GR_FATAL(name, msg) {                                   \
00240     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00241     *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
00242 
00243 #define GR_EMERG(name, msg) {                                   \
00244     gr::logger_ptr logger = gr::logger_get_logger(name);        \
00245     *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
00246 
00247 #define GR_ERRORIF(name, cond, msg) {                                   \
00248     if((cond)) {                                                        \
00249       gr::logger_ptr logger = gr::logger_get_logger(name);              \
00250       *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}       \
00251   }
00252 
00253 #define GR_ASSERT(name, cond, msg) {                                    \
00254     if(!(cond)) {                                                       \
00255       gr::logger_ptr logger = gr::logger_get_logger(name);              \
00256       *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}       \
00257     assert(0);                                                          \
00258   }
00259 
00260   /* LoggerPtr Referenced Macros */
00261 #define GR_LOG_DEBUG(logger, msg) {                                     \
00262     *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
00263 
00264 #define GR_LOG_INFO(logger, msg) {                              \
00265     *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
00266 
00267 #define GR_LOG_NOTICE(logger, msg) {                                    \
00268     *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
00269 
00270 #define GR_LOG_WARN(logger, msg) {                              \
00271     *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
00272 
00273 #define GR_LOG_ERROR(logger, msg) {                                     \
00274     *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
00275 
00276 #define GR_LOG_CRIT(logger, msg) {                              \
00277     *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
00278 
00279 #define GR_LOG_ALERT(logger, msg) {                                     \
00280     *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
00281 
00282 #define GR_LOG_FATAL(logger, msg) {                                     \
00283     *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
00284 
00285 #define GR_LOG_EMERG(logger, msg) {                                     \
00286     *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
00287 
00288 #define GR_LOG_ERRORIF(logger,cond, msg) {                              \
00289     if((cond)) {                                                        \
00290       *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}       \
00291   }
00292 
00293 #define GR_LOG_ASSERT(logger, cond, msg) {                       \
00294     if(!(cond)) {                                                \
00295       *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol; \
00296       assert(0);}                                                \
00297   }
00298 
00299 namespace gr {
00300 
00301   /*!
00302    * \brief Class to control configuration of logger.  
00303    * This is a singleton that cna launch a thread to wathc a config file for changes
00304    * \ingroup logging
00305    */
00306   class logger_config
00307   {
00308   private:
00309     /*! \brief filename of logger config file */
00310     std::string filename;
00311     /*! \brief Period (seconds) over which watcher thread checks config file for changes */
00312     unsigned int watch_period;
00313     /*! \brief Pointer to watch thread for config file changes */
00314     boost::thread *watch_thread;
00315 
00316     /*! \brief Watcher thread method 
00317      * /param filename Name of configuration file
00318      * /param watch_period Seconds between checks for changes in config file
00319      */
00320     static void watch_file(std::string filename,unsigned int watch_period);
00321 
00322     static bool logger_configured;
00323 
00324     logger_config()/*:
00325     rpc_get_filename("logger_config", "filename", &logger_config::get_filename4rpc,
00326       pmt::mp(""), pmt::mp(""), pmt::mp(""),
00327       "", "filename", RPC_PRIVLVL_MIN,
00328       DISPTIME | DISPOPTSTRIP),
00329     rpc_get_watchperiod("logger_config", "watch_period", &logger_config::get_watchperiod4rpc,
00330       pmt::mp(0), pmt::mp(32768), pmt::mp(0),
00331       "", "watch_period", RPC_PRIVLVL_MIN,
00332       DISPTIME | DISPOPTSTRIP),
00333     rpc_get_config("logger_config", "config", &logger_config::get_config4rpc,
00334       pmt::mp(""), pmt::mp(""), pmt::mp(""),
00335       "", "filename", RPC_PRIVLVL_MIN,
00336       DISPTIME | DISPOPTSTRIP),
00337     rpc_set_config("logger_config","config", &logger_config::set_config4rpc,
00338       pmt::mp(""), pmt::mp(""), pmt::mp(""),
00339       "", "filename", RPC_PRIVLVL_MIN,
00340       DISPTIME | DISPOPTSTRIP)
00341                    */
00342     {
00343     }  //!< Constructor
00344 
00345     /*
00346       rpcbasic_register_get<logger_config,std::string> rpc_get_filename;
00347       rpcbasic_register_get<logger_config,int> rpc_get_watchperiod;
00348       rpcbasic_register_get<logger_config,std::string> rpc_get_config;
00349       rpcbasic_register_set<logger_config,std::string> rpc_set_config;
00350     */
00351 
00352     logger_config(logger_config const&);  //!<Copy constructor
00353     void operator=(logger_config const&);  //!<Assignment Operator
00354 
00355     std::string get_filename4rpc() {
00356       return filename;
00357     }
00358     int get_watchperiod4rpc(){return watch_period;};
00359 
00360     std::string get_config4rpc() {
00361       return filename;
00362     }
00363 
00364     void set_config4rpc(std::string set) {
00365       printf("Set string was:%s\n", set.c_str());
00366     }
00367 
00368     /*! \brief destrcutor stops watch thread before exits */
00369     ~logger_config() {
00370       stop_watch();
00371     }
00372 
00373     /*! \brief Instance getter for singleton. Only used by class. */
00374     static logger_config& get_instance(void);
00375 
00376   public:
00377     /*! \brief Getter for config filename */
00378     static std::string get_filename();
00379     /*! \brief Getter for watch period */
00380     static unsigned int get_watch_period();
00381     /*! \brief Method to load configuration
00382      * /param filename Name of configuration file
00383      * /param watch_period Seconds between checks for changes in config file
00384      */
00385     static void load_config(std::string filename,unsigned int watch_period=0);
00386     /*! \brief Method to stop watcher thread */
00387     static void stop_watch();
00388     /*! \brief method to reset logger configuration */
00389     static void reset_config(void);
00390   };
00391 
00392   /*!
00393    * \brief Retrieve a pointer to a logger by name
00394    *
00395    * Retrives a logger pointer
00396    * \p name.
00397    *
00398    * \param name Name of the logger for which a pointer is requested
00399    */
00400   GR_RUNTIME_API logger_ptr logger_get_logger(std::string name);
00401 
00402   /*!
00403    * \brief Load logger's configuration file.
00404    *
00405    * Initialize the GNU Radio logger by loading the configuration file
00406    * \p config_filename.
00407    *
00408    * \param config_filename The configuration file. Set to "" for the
00409    *        basic logger that outputs to the console.
00410    */
00411   GR_RUNTIME_API bool logger_load_config(const std::string &config_filename="");
00412 
00413   /*!
00414    * \brief Reset logger's configuration file.
00415    *
00416    * Remove all appenders from loggers
00417    */
00418   GR_RUNTIME_API void logger_reset_config(void);
00419 
00420   /*!
00421    * \brief Set the logger's output level.
00422    *
00423    * Sets the level of the logger. This takes a string that is
00424    * translated to the standard levels and can be (case insensitive):
00425    *
00426    * \li off , notset
00427    * \li debug
00428    * \li info
00429    * \li notice
00430    * \li warn
00431    * \li error
00432    * \li crit
00433    * \li alert
00434    * \li fatal
00435    * \li emerg
00436    *
00437    * \param logger the logger to set the level of.
00438    * \param level  string to set the level to.
00439    */
00440   GR_RUNTIME_API void logger_set_level(logger_ptr logger,
00441                                        const std::string &level);
00442 
00443   /*!
00444    * \brief Set the logger's output level.
00445    *
00446    * Sets the level of the logger. This takes the actual Log4cpp::Priority
00447    * data type, which can be:
00448    *
00449    * \li log4cpp::Priority::NOTSET
00450    * \li log4cpp::Priority::DEBUG
00451    * \li log4cpp::Priority::INFO
00452    * \li log4cpp::Priority::NOTICE
00453    * \li log4cpp::Priority::WARN
00454    * \li log4cpp::Priority::ERROR
00455    * \li log4cpp::Priority::CRIT
00456    * \li log4cpp::Priority::ALERT
00457    * \li log4cpp::Priority::FATAL
00458    * \li log4cpp::Priority::EMERG
00459    *
00460    * \param logger the logger to set the level of.
00461    * \param level  new logger level of type Log4cpp::Priority
00462    */
00463   GR_RUNTIME_API void logger_set_level(logger_ptr logger,
00464                                        log4cpp::Priority::Value level);
00465 
00466   /*!
00467    * \brief Get the logger's output level.
00468    *
00469    * Gets the level of the logger. This returns a string that
00470    * corresponds to the standard levels and can be (case insensitive):
00471    *
00472    * \li notset
00473    * \li debug
00474    * \li info
00475    * \li notice
00476    * \li warn
00477    * \li error
00478    * \li crit
00479    * \li alert
00480    * \li fatal
00481    * \li emerg
00482    *
00483    * \param logger the logger to get the level of.
00484    * \param level  string to get the level into.
00485    */
00486   GR_RUNTIME_API void logger_get_level(logger_ptr logger, std::string &level);
00487 
00488   /*!
00489    * \brief Get the logger's output level.
00490    *
00491    * Gets the level of the logger. This returns the actual Log4cpp::Level
00492    * data type, which can be:
00493    *
00494    * \li log4cpp::Priority::NOTSET
00495    * \li log4cpp::Priority::DEBUG
00496    * \li log4cpp::Priority::INFO
00497    * \li log4cpp::Priority::NOTICE
00498    * \li log4cpp::Priority::WARN
00499    * \li log4cpp::Priority::ERROR
00500    * \li log4cpp::Priority::CRIT
00501    * \li log4cpp::Priority::ALERT
00502    * \li log4cpp::Priority::FATAL
00503    * \li log4cpp::Priority::EMERG
00504    *
00505    * \param logger the logger to get the level of.
00506    * \param level of the logger.
00507    */
00508   GR_RUNTIME_API void logger_get_level(logger_ptr logger,
00509                                        log4cpp::Priority::Value &level);
00510 
00511   /*!
00512    * \brief Add console appender to a given logger
00513    *
00514    * Add console appender to a given logger
00515    *
00516    * \param logger Logger to which appender will be added
00517    * \param appender Name of appender to add to logger
00518    */
00519   GR_RUNTIME_API void logger_add_appender(logger_ptr logger,
00520                                           std::string appender);
00521 
00522   /*!
00523    * \brief Add console appender to a given logger
00524    *
00525    * Add console appender to a given logger
00526    *
00527    * \param logger Logger to which appender will be added
00528    * \param target Std target to write 'cout' or 'cerr' (default is cout)
00529    * \param pattern Formating pattern for log messages
00530    */
00531   GR_RUNTIME_API void logger_add_console_appender(logger_ptr logger,
00532                                                   std::string target,
00533                                                   std::string pattern);
00534 
00535   /*!
00536    * \brief Add file appender to a given logger
00537    *
00538    * Add file appender to a given logger
00539    *
00540    * \param logger Logger to which appender will be added
00541    * \param filename File to which log will be written
00542    * \param append Overwrite or append to log file
00543    * \param pattern Formating pattern for log messages
00544    */
00545   GR_RUNTIME_API void logger_add_file_appender(logger_ptr logger,
00546                                                std::string filename,
00547                                                bool append, std::string pattern);
00548 
00549   /*!
00550    * \brief Add rolling file appender to a given logger
00551    *
00552    * Add rolling file appender to a given logger
00553    *
00554    * \param logger Logger to which appender will be added
00555    * \param filename File to which log will be written
00556    * \param filesize Sizez of files to write
00557    * \param bkup_index Number of files to write
00558    * \param append Overwrite or append to log file
00559    * \param mode Permissions to set on log file
00560    * \param pattern Formating pattern for log messages
00561    */
00562   GR_RUNTIME_API void logger_add_rollingfile_appender(logger_ptr logger, std::string filename,
00563                                                       size_t filesize, int bkup_index, bool append,
00564                                                       mode_t mode,std::string pattern);
00565 
00566   /*!
00567    * \brief Add rolling file appender to a given logger
00568    *
00569    * Add rolling file appender to a given logger
00570    *
00571    * \return vector of string names of loggers 
00572    */
00573   GR_RUNTIME_API std::vector<std::string> logger_get_logger_names(void);
00574 
00575 } /* namespace gr */
00576 
00577 #endif /* HAVE_LOG4CPP */
00578 
00579   // If Logger disable do nothing
00580 #else /* ENABLE_GR_LOG */
00581 
00582 namespace gr {
00583   typedef void* logger_ptr;
00584 } /* namespace gr */
00585 
00586 #define GR_LOG_DECLARE_LOGPTR(logger)
00587 #define GR_LOG_ASSIGN_LOGPTR(logger,name)
00588 #define GR_CONFIG_LOGGER(config)
00589 #define GR_CONFIG_AND_WATCH_LOGGER(config,period)
00590 #define GR_LOG_GETLOGGER(logger, name) 
00591 #define GR_SET_LEVEL(name, level)
00592 #define GR_LOG_SET_LEVEL(logger, level) 
00593 #define GR_GET_LEVEL(name, level)
00594 #define GR_LOG_GET_LEVEL(logger, level)
00595 #define GR_ADD_APPENDER(name,appender)
00596 #define GR_LOG_ADD_APPENDER(logger,appender)
00597 #define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
00598 #define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
00599 #define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
00600 #define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
00601 #define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
00602 #define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
00603 #define GR_GET_LOGGER_NAMES(names)
00604 #define GR_RESET_CONFIGURATION()
00605 #define GR_DEBUG(name, msg)
00606 #define GR_INFO(name, msg)
00607 #define GR_NOTICE(name, msg)
00608 #define GR_WARN(name, msg)
00609 #define GR_ERROR(name, msg)
00610 #define GR_ALERT(name, msg)
00611 #define GR_CRIT(name, msg)
00612 #define GR_FATAL(name, msg)
00613 #define GR_EMERG(name, msg)
00614 #define GR_ERRORIF(name, cond, msg)
00615 #define GR_ASSERT(name, cond, msg)
00616 #define GR_LOG_DEBUG(logger, msg)
00617 #define GR_LOG_INFO(logger, msg)
00618 #define GR_LOG_NOTICE(logger, msg)
00619 #define GR_LOG_WARN(logger, msg)
00620 #define GR_LOG_ERROR(logger, msg)
00621 #define GR_LOG_ALERT(logger, msg)
00622 #define GR_LOG_CRIT(logger, msg)
00623 #define GR_LOG_FATAL(logger, msg)
00624 #define GR_LOG_EMERG(logger, msg)
00625 #define GR_LOG_ERRORIF(logger, cond, msg)
00626 #define GR_LOG_ASSERT(logger, cond, msg)
00627 
00628 #endif /* ENABLE_GR_LOG */
00629 
00630 namespace gr {
00631 
00632   // Even if logger is disabled we'll need for methods below to exist in python.
00633   // The macros these call will be disabled if ENABLE_GR_LOG is undefined
00634 
00635   /********************* Start  Classes and Methods for Python ******************/
00636   /*!
00637    * \brief Logger class for referencing loggers in python.  Not
00638    * needed in C++ (use macros) Wraps and manipulates loggers for
00639    * python as python has no macros
00640    * \ingroup logging
00641    *
00642    */
00643   class logger
00644   {
00645   private:
00646     /*! \brief logger pointer to logger associated wiith this wrapper class */
00647     logger_ptr d_logger;
00648   public:
00649     /*!
00650      * \brief contructor Provide name of logger to associate with this class
00651      * \param logger_name Name of logger associated with class
00652      */
00653     logger(std::string logger_name) {
00654       GR_LOG_ASSIGN_LOGPTR(d_logger,logger_name);
00655     };
00656 
00657     /*! \brief Destructor */
00658     ~logger(){;}
00659 
00660     // Wrappers for logging macros
00661     /*! \brief inline function, wrapper to set the logger level */
00662     void set_level(std::string level){GR_LOG_SET_LEVEL(d_logger,level);}
00663 
00664     /*! \brief inline function, wrapper to get the logger level */
00665     void get_level(std::string &level){GR_LOG_GET_LEVEL(d_logger,level);}
00666 
00667     /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
00668     void debug(std::string msg){GR_LOG_DEBUG(d_logger,msg);};
00669 
00670     /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
00671     void info(std::string msg){GR_LOG_INFO(d_logger,msg);}
00672 
00673     /*! \brief inline function, wrapper for NOTICE message */
00674     void notice(std::string msg){GR_LOG_NOTICE(d_logger,msg);}
00675 
00676     /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
00677     void warn(std::string msg){GR_LOG_WARN(d_logger,msg);}
00678 
00679     /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
00680     void error(std::string msg){GR_LOG_ERROR(d_logger,msg);}
00681 
00682     /*! \brief inline function, wrapper for NOTICE message */
00683     void crit(std::string msg){GR_LOG_CRIT(d_logger,msg);}
00684 
00685     /*! \brief inline function, wrapper for ALERT message */
00686     void alert(std::string msg){GR_LOG_ALERT(d_logger,msg);}
00687 
00688     /*! \brief inline function, wrapper for FATAL message */
00689     void fatal(std::string msg){GR_LOG_FATAL(d_logger,msg);}
00690 
00691     /*! \brief inline function, wrapper for EMERG message */
00692     void emerg(std::string msg){GR_LOG_EMERG(d_logger,msg);}
00693 
00694     /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
00695     void errorIF(bool cond,std::string msg){GR_LOG_ERRORIF(d_logger,cond,msg);}
00696 
00697     /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
00698     void log_assert(bool cond,std::string msg){GR_LOG_ASSERT(d_logger,cond,msg);}
00699 
00700     /*! \brief inline function, Method to add appender to logger by
00701         name (define appender in conf file) */
00702     void add_appender(std::string appender) {
00703       GR_LOG_ADD_APPENDER(d_logger, appender);
00704     }
00705 
00706     /*! \brief inline function, Method to add console appender to logger */
00707     void add_console_appender(std::string target,std::string pattern) {
00708       GR_LOG_ADD_CONSOLE_APPENDER(d_logger, target, pattern);
00709     }
00710 
00711     /*! \brief inline function, Method to add file appender to logger */
00712     void add_file_appender(std::string filename, bool append, std::string pattern) {
00713       GR_LOG_ADD_FILE_APPENDER(d_logger, filename, append, pattern);
00714     }
00715 
00716     /*! \brief inline function, Method to add rolling file appender to logger */
00717     void add_rollingfile_appender(std::string filename, size_t filesize,
00718                                   int bkup_index, bool append, mode_t mode,
00719                                   std::string pattern) {
00720       GR_LOG_ADD_ROLLINGFILE_APPENDER(d_logger,filename,filesize,
00721                                       bkup_index,append,mode,pattern);
00722     }
00723   };
00724 
00725 } /* namespace gr */
00726 
00727 /**************** Start Configuration Class and Methods for Python ************/
00728 /*!
00729  * \brief Function to call configuration macro from python.  
00730  *        Note: Configuration is only updated if filename or watch_period has changed.
00731  * \param config_filename  Name of configuration file
00732  * \param watch_period Seconds to wait between checking for changes in conf file.
00733  *        Watch_period defaults to 0 in which case the file is not watched for changes
00734  */
00735 GR_RUNTIME_API void gr_logger_config(const std::string config_filename,
00736                                      unsigned int watch_period = 0);
00737 
00738 /*!
00739  * \brief Function to return logger names to python
00740  * \return Vector of name strings
00741  *
00742  */
00743 GR_RUNTIME_API std::vector<std::string> gr_logger_get_logger_names(void);
00744 
00745 /*!
00746  * \brief Function to reset logger configuration from python
00747  * 
00748  */
00749 GR_RUNTIME_API void gr_logger_reset_config(void);
00750 
00751 #endif /* INCLUDED_GR_LOGGER_H */