blob: 68a8762538885096d613396be9193ea2e6ece602 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080019 */
20
21#ifndef LOGGING_H
22#define LOGGING_H
23
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080024#include "core/chronoshare-config.hpp"
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080025
26#ifdef HAVE_LOG4CXX
27
28#include <log4cxx/logger.h>
29
Alexander Afanasyev47cf2ef2013-01-28 15:13:47 -080030#define MEMBER_LOGGER \
31 static log4cxx::LoggerPtr staticModuleLogger;
32
33#define INIT_MEMBER_LOGGER(className,name) \
34 log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name);
35
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080036#define INIT_LOGGER(name) \
37 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
38
39#define _LOG_DEBUG(x) \
40 LOG4CXX_DEBUG(staticModuleLogger, x);
41
42#define _LOG_TRACE(x) \
43 LOG4CXX_TRACE(staticModuleLogger, x);
44
45#define _LOG_FUNCTION(x) \
46 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
47
48#define _LOG_FUNCTION_NOARGS \
49 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
50
51#define _LOG_ERROR(x) \
52 LOG4CXX_ERROR(staticModuleLogger, x);
53
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080054#define _LOG_ERROR_COND(cond,x) \
55 if (cond) { _LOG_ERROR(x) }
56
57#define _LOG_DEBUG_COND(cond,x) \
58 if (cond) { _LOG_DEBUG(x) }
59
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080060void
61INIT_LOGGERS ();
62
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080063#else // else HAVE_LOG4CXX
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080064
65#define INIT_LOGGER(name)
66#define _LOG_FUNCTION(x)
67#define _LOG_FUNCTION_NOARGS
68#define _LOG_TRACE(x)
69#define INIT_LOGGERS(x)
70#define _LOG_ERROR(x)
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080071#define _LOG_ERROR_COND(cond,x)
72#define _LOG_DEBUG_COND(cond,x)
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080073
Alexander Afanasyev47cf2ef2013-01-28 15:13:47 -080074#define MEMBER_LOGGER
75#define INIT_MEMBER_LOGGER(className,name)
76
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080077#ifdef _DEBUG
78
79#include <boost/thread/thread.hpp>
80#include <boost/date_time/posix_time/posix_time.hpp>
81#include <iostream>
82
83#define _LOG_DEBUG(x) \
Alexander Afanasyev02a86ec2013-03-04 13:09:31 -080084 std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << std::endl;
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080085
86#else
87#define _LOG_DEBUG(x)
88#endif
89
90#endif // HAVE_LOG4CXX
91
92#endif // LOGGING_H