00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef LOGGING_H__
00040 #define LOGGING_H__
00041
00042 #include <iostream>
00043 #include <cstdlib>
00044 #include "ariba/config.h"
00045
00046 #ifdef HAVE_LOG4CXX_LOGGER_H
00047 #include <log4cxx/logger.h>
00048 #include <log4cxx/basicconfigurator.h>
00049 #endif // HAVE_LOG4CXX_LOGGER_H
00050
00051 #ifdef LOGCOLORS
00052
00053 #define colorDefault { std::cout << "\033[0m"; }
00054 #define colorDebug { std::cout << "\033[0;33m"; }
00055 #define colorInfo { std::cout << "\033[0;32m"; }
00056 #define colorWarn { std::cout << "\033[0;34m"; }
00057 #define colorError { std::cout << "\033[0;31m"; }
00058
00059 #else
00060
00061 #define colorDefault { }
00062 #define colorDebug { }
00063 #define colorInfo { }
00064 #define colorWarn { }
00065 #define colorError { }
00066
00067 #endif // ENABLE_LOGCOLORS
00068
00069
00070 #ifdef HAVE_LOG4CXX_LOGGER_H
00071
00072 #define use_logging_h(x) \
00073 private: static log4cxx::LoggerPtr logger;
00074
00075 #define use_logging_cpp(x) \
00076 log4cxx::LoggerPtr x::logger(log4cxx::Logger::getLogger(#x));
00077
00078 #define logging_trace(x) { LOG4CXX_TRACE(logger,x); }
00079 #define logging_debug(x) {colorDebug; LOG4CXX_DEBUG(logger,x); colorDefault; }
00080 #define logging_info(x) {colorInfo; LOG4CXX_INFO(logger,x); colorDefault; }
00081 #define logging_warn(x) {colorWarn; LOG4CXX_WARN(logger,x); colorDefault; }
00082 #define logging_error(x) {colorError; LOG4CXX_ERROR(logger,x); colorDefault; }
00083 #define logging_fatal(x) {colorError; LOG4CXX_FATAL(logger,x); colorDefault; exit(-1); }
00084
00085 #else // HAVE_LOG4CXX_LOGGER_H
00086
00087 #define use_logging_h(x)
00088
00089 #define use_logging_cpp(x)
00090
00091 #define logging_stdout(x) std::cout << x << std::endl;
00092
00093 #define logging_trace(x)
00094 #define logging_debug(x) {colorDebug; logging_stdout(x); colorDefault; }
00095 #define logging_info(x) {colorInfo; logging_stdout(x); colorDefault; }
00096 #define logging_warn(x) {colorWarn; logging_stdout(x); colorDefault; }
00097 #define logging_error(x) {colorError; logging_stdout(x); colorDefault; }
00098 #define logging_fatal(x) {colorError; logging_stdout(x); colorDefault; exit(-1); }
00099
00100 #endif // HAVE_LOG4CXX_LOGGER_H
00101
00102 #endif //LOGGING_H__