blob: 9370af0f7822c7532669b4458d671029114faab6 [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
Jeff Thompsonb7523002013-10-09 10:25:00 -070014#ifdef NDN_CPP_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
Jeff Thompsonb7523002013-10-09 10:25:00 -070051#else // else NDN_CPP_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 Afanasyev1e0a0772014-01-28 20:07:07 -080070 { std::clog << s.substr(0, s.size() - 1) << " " << x << std::endl; }
Jeff Thompsone2cd5872013-09-19 15:53:29 -070071
72#else
73#define _LOG_DEBUG(x)
74#endif
75
Jeff Thompsonb7523002013-10-09 10:25:00 -070076#endif // NDN_CPP_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070077
78#endif