logging.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_LOGGING_HPP
24 #define NDN_LOGGING_HPP
25 
26 #include <ndn-cpp/common.hpp>
27 
28 #if NDN_CPP_HAVE_LOG4CXX
29 
30 #include <log4cxx/logger.h>
31 
32 #define MEMBER_LOGGER \
33  static log4cxx::LoggerPtr staticModuleLogger;
34 
35 #define INIT_MEMBER_LOGGER(className,name) \
36  log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name);
37 
38 #define INIT_LOGGER(name) \
39  static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
40 
41 #define _LOG_DEBUG(x) \
42  LOG4CXX_DEBUG(staticModuleLogger, x);
43 
44 #define _LOG_TRACE(x) \
45  LOG4CXX_TRACE(staticModuleLogger, x);
46 
47 #define _LOG_FUNCTION(x) \
48  LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
49 
50 #define _LOG_FUNCTION_NOARGS \
51  LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
52 
53 #define _LOG_ERROR(x) \
54  LOG4CXX_ERROR(staticModuleLogger, x);
55 
56 #define _LOG_ERROR_COND(cond,x) \
57  if (cond) { _LOG_ERROR(x) }
58 
59 #define _LOG_DEBUG_COND(cond,x) \
60  if (cond) { _LOG_DEBUG(x) }
61 
62 void
63 INIT_LOGGERS ();
64 
65 #else // else NDN_CPP_HAVE_LOG4CXX
66 
67 #define INIT_LOGGER(name)
68 #define _LOG_FUNCTION(x)
69 #define _LOG_FUNCTION_NOARGS
70 #define _LOG_TRACE(x)
71 #define INIT_LOGGERS(x)
72 #define _LOG_ERROR_COND(cond,x)
73 #define _LOG_DEBUG_COND(cond,x)
74 
75 #define MEMBER_LOGGER
76 #define INIT_MEMBER_LOGGER(className,name)
77 
78 #ifdef _DEBUG
79 
80 #include <time.h>
81 #include <iostream>
82 
83 #define _LOG_DEBUG(x) \
84  { time_t now = time(0); std::string s = std::string(ctime(&now)); std::clog << s.substr(0, s.size() - 1) << " " << x << std::endl; }
85 #define _LOG_ERROR(x) _LOG_DEBUG(x)
86 
87 #else
88 #define _LOG_DEBUG(x)
89 #define _LOG_ERROR(x)
90 #endif
91 
92 #endif // NDN_CPP_HAVE_LOG4CXX
93 
94 #endif