blob: 5ee958c39b55fe22e25819b75a01fe773321cfbd [file] [log] [blame]
Jeff Thompsone2cd5872013-09-19 15:53:29 -07001/* -*- 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 Thompsone589c3f2013-10-12 17:30:50 -070010#define NDN_LOGGING_HPP
Jeff Thompsone2cd5872013-09-19 15:53:29 -070011
Alexander Afanasyev19508852014-01-29 01:01:51 -080012#include "../common.hpp"
Jeff Thompsone2cd5872013-09-19 15:53:29 -070013
Alexander Afanasyev766cea72014-04-24 19:16:42 -070014#ifdef NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070015
16#include <log4cxx/logger.h>
17
18#define MEMBER_LOGGER \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070019 static log4cxx::LoggerPtr staticModuleLogger
Jeff Thompsone2cd5872013-09-19 15:53:29 -070020
21#define INIT_MEMBER_LOGGER(className,name) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070022 log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070023
24#define INIT_LOGGER(name) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070025 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070026
27#define _LOG_DEBUG(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070028 LOG4CXX_DEBUG(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070029
30#define _LOG_TRACE(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070031 LOG4CXX_TRACE(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070032
33#define _LOG_FUNCTION(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070034 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")")
Jeff Thompsone2cd5872013-09-19 15:53:29 -070035
36#define _LOG_FUNCTION_NOARGS \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070037 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()")
Jeff Thompsone2cd5872013-09-19 15:53:29 -070038
39#define _LOG_ERROR(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070040 LOG4CXX_ERROR(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070041
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
48void
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070049INIT_LOGGERS()
Jeff Thompsone2cd5872013-09-19 15:53:29 -070050
Alexander Afanasyev766cea72014-04-24 19:16:42 -070051#else // else NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070052
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070053#define INIT_LOGGER(name) struct LOGGING_DISABLED
Jeff Thompsone2cd5872013-09-19 15:53:29 -070054#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 Thompsone2cd5872013-09-19 15:53:29 -070067#include <iostream>
68
69#define _LOG_DEBUG(x) \
Alexander Afanasyev766cea72014-04-24 19:16:42 -070070 { std::clog << x << std::endl; }
Jeff Thompsone2cd5872013-09-19 15:53:29 -070071
72#else
73#define _LOG_DEBUG(x)
74#endif
75
Alexander Afanasyev766cea72014-04-24 19:16:42 -070076#endif // NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070077
78#endif