blob: 2ac782a20729ae3e5f9c1ce0a225116c03ed2d69 [file] [log] [blame]
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyev8722d872014-07-02 13:00:29 -07003 * Copyright (c) 2012-2014 University of California, Los Angeles
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * You should have received a copy of the GNU General Public License along with
17 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
20 * @author Chaoyi Bian <bcy@pku.edu.cn>
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070022 */
23
Yingdi Yua585d4d2014-09-20 21:55:47 -070024#ifndef CHRONOSYNC_LOGGER_HPP
25#define CHRONOSYNC_LOGGER_HPP
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070026
27#ifdef HAVE_LOG4CXX
28
29#include <log4cxx/logger.h>
30
31#define INIT_LOGGER(name) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070032 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070033
34#define _LOG_DEBUG(x) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070035 LOG4CXX_DEBUG(staticModuleLogger, x)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070036
37#define _LOG_TRACE(x) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070038 LOG4CXX_TRACE(staticModuleLogger, x)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070039
40#define _LOG_FUNCTION(x) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070041 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")")
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070042
43#define _LOG_FUNCTION_NOARGS \
Yingdi Yua585d4d2014-09-20 21:55:47 -070044 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()")
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070045
Zhenkai Zhu26cd6e32012-10-05 13:10:58 -070046#define _LOG_ERROR(x) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070047 LOG4CXX_ERROR(staticModuleLogger, x)
Zhenkai Zhu26cd6e32012-10-05 13:10:58 -070048
Yingdi Yua585d4d2014-09-20 21:55:47 -070049#else // HAVE_LOG4CXX
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070050
51#define INIT_LOGGER(name)
52#define _LOG_FUNCTION(x)
53#define _LOG_FUNCTION_NOARGS
54#define _LOG_TRACE(x)
55#define INIT_LOGGERS(x)
Zhenkai Zhu26cd6e32012-10-05 13:10:58 -070056#define _LOG_ERROR(x)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070057
58#ifdef _DEBUG
59
Yingdi Yu906c2ea2014-10-31 11:24:50 -070060#include <thread>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070061#include <iostream>
Yingdi Yu906c2ea2014-10-31 11:24:50 -070062#include <ndn-cxx/util/time.hpp>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070063
64#define _LOG_DEBUG(x) \
Yingdi Yu906c2ea2014-10-31 11:24:50 -070065 std::clog << ndn::time::system_clock::now() << " " << std::this_thread::get_id() << \
Yingdi Yuf7ede412014-08-30 20:37:52 -070066 " " << x << std::endl
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070067
Yingdi Yua585d4d2014-09-20 21:55:47 -070068#else // _DEBUG
69
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070070#define _LOG_DEBUG(x)
Yingdi Yua585d4d2014-09-20 21:55:47 -070071
72#endif // _DEBUG
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070073
74#endif // HAVE_LOG4CXX
75
Yingdi Yua585d4d2014-09-20 21:55:47 -070076#endif // CHRONOSYNC_LOGGER_HPP