Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 5 | * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #ifndef NDN_LOGGING_HPP |
| 10 | #define NDN_LOGGING_HPP |
| 11 | |
| 12 | #include "../../config.h" |
| 13 | |
| 14 | #ifdef HAVE_LOG4CXX |
| 15 | |
| 16 | #include <log4cxx/logger.h> |
| 17 | |
| 18 | #define MEMBER_LOGGER \ |
| 19 | static log4cxx::LoggerPtr staticModuleLogger; |
| 20 | |
| 21 | #define INIT_MEMBER_LOGGER(className,name) \ |
| 22 | log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 23 | |
| 24 | #define INIT_LOGGER(name) \ |
| 25 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 26 | |
| 27 | #define _LOG_DEBUG(x) \ |
| 28 | LOG4CXX_DEBUG(staticModuleLogger, x); |
| 29 | |
| 30 | #define _LOG_TRACE(x) \ |
| 31 | LOG4CXX_TRACE(staticModuleLogger, x); |
| 32 | |
| 33 | #define _LOG_FUNCTION(x) \ |
| 34 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")"); |
| 35 | |
| 36 | #define _LOG_FUNCTION_NOARGS \ |
| 37 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()"); |
| 38 | |
| 39 | #define _LOG_ERROR(x) \ |
| 40 | LOG4CXX_ERROR(staticModuleLogger, x); |
| 41 | |
| 42 | #define _LOG_ERROR_COND(cond,x) \ |
| 43 | if (cond) { _LOG_ERROR(x) } |
| 44 | |
| 45 | #define _LOG_DEBUG_COND(cond,x) \ |
| 46 | if (cond) { _LOG_DEBUG(x) } |
| 47 | |
| 48 | void |
| 49 | INIT_LOGGERS (); |
| 50 | |
| 51 | #else // else HAVE_LOG4CXX |
| 52 | |
| 53 | #define INIT_LOGGER(name) |
| 54 | #define _LOG_FUNCTION(x) |
| 55 | #define _LOG_FUNCTION_NOARGS |
| 56 | #define _LOG_TRACE(x) |
| 57 | #define INIT_LOGGERS(x) |
| 58 | #define _LOG_ERROR(x) |
| 59 | #define _LOG_ERROR_COND(cond,x) |
| 60 | #define _LOG_DEBUG_COND(cond,x) |
| 61 | |
| 62 | #define MEMBER_LOGGER |
| 63 | #define INIT_MEMBER_LOGGER(className,name) |
| 64 | |
| 65 | #ifdef _DEBUG |
| 66 | |
| 67 | #include <sys/time.h> |
| 68 | #include <iostream> |
| 69 | |
| 70 | #define _LOG_DEBUG(x) \ |
| 71 | { time_t now = time(0); std::string s = std::string(ctime(&now)); std::clog << s.substr(0, s.size() - 1) << " " << x << std::endl; } |
| 72 | |
| 73 | #else |
| 74 | #define _LOG_DEBUG(x) |
| 75 | #endif |
| 76 | |
| 77 | #endif // HAVE_LOG4CXX |
| 78 | |
| 79 | #endif |