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 |
Jeff Thompson | e589c3f | 2013-10-12 17:30:50 -0700 | [diff] [blame] | 10 | #define NDN_LOGGING_HPP |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | 1950885 | 2014-01-29 01:01:51 -0800 | [diff] [blame] | 12 | #include "../common.hpp" |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | b752300 | 2013-10-09 10:25:00 -0700 | [diff] [blame] | 14 | #ifdef NDN_CPP_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 15 | |
| 16 | #include <log4cxx/logger.h> |
| 17 | |
| 18 | #define MEMBER_LOGGER \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 19 | static log4cxx::LoggerPtr staticModuleLogger |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 20 | |
| 21 | #define INIT_MEMBER_LOGGER(className,name) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 22 | log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 23 | |
| 24 | #define INIT_LOGGER(name) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 25 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 26 | |
| 27 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 28 | LOG4CXX_DEBUG(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 29 | |
| 30 | #define _LOG_TRACE(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 31 | LOG4CXX_TRACE(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 32 | |
| 33 | #define _LOG_FUNCTION(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 34 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")") |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 35 | |
| 36 | #define _LOG_FUNCTION_NOARGS \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 37 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()") |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 38 | |
| 39 | #define _LOG_ERROR(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 40 | LOG4CXX_ERROR(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 49 | INIT_LOGGERS() |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 50 | |
Jeff Thompson | b752300 | 2013-10-09 10:25:00 -0700 | [diff] [blame] | 51 | #else // else NDN_CPP_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame^] | 53 | #define INIT_LOGGER(name) struct LOGGING_DISABLED |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 67 | #include <iostream> |
| 68 | |
| 69 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 70 | { std::clog << s.substr(0, s.size() - 1) << " " << x << std::endl; } |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 71 | |
| 72 | #else |
| 73 | #define _LOG_DEBUG(x) |
| 74 | #endif |
| 75 | |
Jeff Thompson | b752300 | 2013-10-09 10:25:00 -0700 | [diff] [blame] | 76 | #endif // NDN_CPP_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 77 | |
| 78 | #endif |