Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
| 13 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NDN_LOGGING_HPP |
Jeff Thompson | e589c3f | 2013-10-12 17:30:50 -0700 | [diff] [blame] | 17 | #define NDN_LOGGING_HPP |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 18 | |
Alexander Afanasyev | 1950885 | 2014-01-29 01:01:51 -0800 | [diff] [blame] | 19 | #include "../common.hpp" |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 21 | #ifdef NDN_CXX_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 22 | |
| 23 | #include <log4cxx/logger.h> |
| 24 | |
| 25 | #define MEMBER_LOGGER \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 26 | static log4cxx::LoggerPtr staticModuleLogger |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 27 | |
| 28 | #define INIT_MEMBER_LOGGER(className,name) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 29 | log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 30 | |
| 31 | #define INIT_LOGGER(name) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 32 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 33 | |
| 34 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 35 | LOG4CXX_DEBUG(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 36 | |
| 37 | #define _LOG_TRACE(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 38 | LOG4CXX_TRACE(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 39 | |
| 40 | #define _LOG_FUNCTION(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 41 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")") |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 42 | |
| 43 | #define _LOG_FUNCTION_NOARGS \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 44 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()") |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 45 | |
| 46 | #define _LOG_ERROR(x) \ |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 47 | LOG4CXX_ERROR(staticModuleLogger, x) |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 48 | |
| 49 | #define _LOG_ERROR_COND(cond,x) \ |
| 50 | if (cond) { _LOG_ERROR(x) } |
| 51 | |
| 52 | #define _LOG_DEBUG_COND(cond,x) \ |
| 53 | if (cond) { _LOG_DEBUG(x) } |
| 54 | |
| 55 | void |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 56 | INIT_LOGGERS() |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 58 | #else // else NDN_CXX_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 60 | #define INIT_LOGGER(name) struct LOGGING_DISABLED |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 61 | #define _LOG_FUNCTION(x) |
| 62 | #define _LOG_FUNCTION_NOARGS |
| 63 | #define _LOG_TRACE(x) |
| 64 | #define INIT_LOGGERS(x) |
| 65 | #define _LOG_ERROR(x) |
| 66 | #define _LOG_ERROR_COND(cond,x) |
| 67 | #define _LOG_DEBUG_COND(cond,x) |
| 68 | |
| 69 | #define MEMBER_LOGGER |
| 70 | #define INIT_MEMBER_LOGGER(className,name) |
| 71 | |
| 72 | #ifdef _DEBUG |
| 73 | |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 74 | #include <iostream> |
| 75 | |
| 76 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 77 | { std::clog << x << std::endl; } |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 78 | |
| 79 | #else |
| 80 | #define _LOG_DEBUG(x) |
| 81 | #endif |
| 82 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 83 | #endif // NDN_CXX_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 84 | |
| 85 | #endif |