Ignore:
Timestamp:
Apr 7, 2011, 4:36:00 PM (14 years ago)
Author:
Christoph Mayer
Message:

-logging optional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/logging/Logging.h

    r7748 r9737  
    4545
    4646#ifdef HAVE_LOG4CXX_LOGGER_H
    47 #include <log4cxx/logger.h>
    48 #include <log4cxx/basicconfigurator.h>
     47        #include <log4cxx/logger.h>
     48        #include <log4cxx/basicconfigurator.h>
    4949#endif // HAVE_LOG4CXX_LOGGER_H
    5050
    5151#ifdef LOGCOLORS
    52 
    5352  #define colorDefault { std::cout << "\033[0m";  } /*reset*/
    5453  #define colorDebug   { std::cout << "\033[0;33m"; } /*cyan*/
     
    5857
    5958#else
    60 
    6159  #define colorDefault { }
    6260  #define colorDebug   { }
     
    6462  #define colorWarn    { }
    6563  #define colorError   { }
    66 
    6764#endif // ENABLE_LOGCOLORS
    6865
     
    8380  #define logging_fatal(x)  {colorError; LOG4CXX_FATAL(logger,x); colorDefault; exit(-1); }
    8481
     82  #define logging_rootlevel_debug()       {log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug()); }
     83  #define logging_rootlevel_info()        {log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo() ); }
     84  #define logging_rootlevel_warn()        {log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getWarn() ); }
     85  #define logging_rootlevel_error()       {log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getError()); }
     86
     87  #define logging_classlevel_debug(x) {log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(x)); if(logger != NULL) logger->setLevel(log4cxx::Level::getDebug()); }
     88  #define logging_classlevel_info(x)  {log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(x)); if(logger != NULL) logger->setLevel(log4cxx::Level::getInfo());  }
     89  #define logging_classlevel_warn(x)  {log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(x)); if(logger != NULL) logger->setLevel(log4cxx::Level::getWarn());  }
     90  #define logging_classlevel_error(x) {log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(x)); if(logger != NULL) logger->setLevel(log4cxx::Level::getError()); }
     91
    8592#else // HAVE_LOG4CXX_LOGGER_H
    8693
    8794  #define use_logging_h(x)
    88 
    8995  #define use_logging_cpp(x)
    9096
    9197  #define logging_stdout(x) std::cout << x << std::endl;
    9298
    93   #define logging_trace(x)
    94   #define logging_debug(x)  {colorDebug; logging_stdout(x); colorDefault;           }
    95   #define logging_info(x)   {colorInfo;  logging_stdout(x);  colorDefault;           }
    96   #define logging_warn(x)   {colorWarn;  logging_stdout(x);  colorDefault;           }
    97   #define logging_error(x)  {colorError; logging_stdout(x); colorDefault;           }
    98   #define logging_fatal(x)  {colorError; logging_stdout(x); colorDefault; exit(-1); }
     99  static int __loglevel__ = 2; //default is info
     100
     101  #define logging_trace(x)  {            logging_stdout(x);                         }
     102  #define logging_debug(x)  {if(__loglevel__ <= 1){ colorDebug; logging_stdout(x); colorDefault; }}
     103  #define logging_info(x)   {if(__loglevel__ <= 2){ colorInfo;  logging_stdout(x); colorDefault; }}
     104  #define logging_warn(x)   {if(__loglevel__ <= 3){ colorWarn;  logging_stdout(x); colorDefault; }}
     105  #define logging_error(x)  {                     return; colorError; logging_stdout(x); colorDefault;           }
     106  #define logging_fatal(x)  {                     return; colorError; logging_stdout(x); colorDefault; exit(-1); }
     107
     108  #define logging_rootlevel_debug()       {__loglevel__ = 1;}
     109  #define logging_rootlevel_info()        {__loglevel__ = 2;}
     110  #define logging_rootlevel_warn()        {__loglevel__ = 3;}
     111  #define logging_rootlevel_error()       {__loglevel__ = 4;}
     112
     113  #define logging_classlevel_debug(x) {std::cout << "individual class logging only available with log4cxx library" << std::endl;}
     114  #define logging_classlevel_info(x)  {std::cout << "individual class logging only available with log4cxx library" << std::endl;}
     115  #define logging_classlevel_warn(x)  {std::cout << "individual class logging only available with log4cxx library" << std::endl;}
     116  #define logging_classlevel_error(x) {std::cout << "individual class logging only available with log4cxx library" << std::endl;}
    99117
    100118#endif // HAVE_LOG4CXX_LOGGER_H
Note: See TracChangeset for help on using the changeset viewer.