blob: 5ac0463c190de3efbf5c097d1836f5ca33cc50f7 [file] [log] [blame]
Jeff Thompsone2cd5872013-09-19 15:53:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Thompsone2cd5872013-09-19 15:53:29 -070014 */
15
16#ifndef NDN_LOGGING_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -070017#define NDN_LOGGING_HPP
Jeff Thompsone2cd5872013-09-19 15:53:29 -070018
Alexander Afanasyev19508852014-01-29 01:01:51 -080019#include "../common.hpp"
Jeff Thompsone2cd5872013-09-19 15:53:29 -070020
Alexander Afanasyev766cea72014-04-24 19:16:42 -070021#ifdef NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070022
23#include <log4cxx/logger.h>
24
25#define MEMBER_LOGGER \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070026 static log4cxx::LoggerPtr staticModuleLogger
Jeff Thompsone2cd5872013-09-19 15:53:29 -070027
28#define INIT_MEMBER_LOGGER(className,name) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070029 log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070030
31#define INIT_LOGGER(name) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070032 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070033
34#define _LOG_DEBUG(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070035 LOG4CXX_DEBUG(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070036
37#define _LOG_TRACE(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070038 LOG4CXX_TRACE(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070039
40#define _LOG_FUNCTION(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070041 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")")
Jeff Thompsone2cd5872013-09-19 15:53:29 -070042
43#define _LOG_FUNCTION_NOARGS \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070044 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()")
Jeff Thompsone2cd5872013-09-19 15:53:29 -070045
46#define _LOG_ERROR(x) \
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070047 LOG4CXX_ERROR(staticModuleLogger, x)
Jeff Thompsone2cd5872013-09-19 15:53:29 -070048
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
55void
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070056INIT_LOGGERS()
Jeff Thompsone2cd5872013-09-19 15:53:29 -070057
Alexander Afanasyev766cea72014-04-24 19:16:42 -070058#else // else NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070059
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070060#define INIT_LOGGER(name) struct LOGGING_DISABLED
Jeff Thompsone2cd5872013-09-19 15:53:29 -070061#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 Thompsone2cd5872013-09-19 15:53:29 -070074#include <iostream>
75
76#define _LOG_DEBUG(x) \
Alexander Afanasyev766cea72014-04-24 19:16:42 -070077 { std::clog << x << std::endl; }
Jeff Thompsone2cd5872013-09-19 15:53:29 -070078
79#else
80#define _LOG_DEBUG(x)
81#endif
82
Alexander Afanasyev766cea72014-04-24 19:16:42 -070083#endif // NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070084
85#endif