blob: c4eee030f91c4f73cea79081c888cc494e07aa8e [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
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070060#include <boost/date_time/posix_time/posix_time.hpp>
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070061#include <boost/thread/thread_time.hpp>
62#include <boost/thread/thread.hpp>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070063#include <iostream>
64
65#define _LOG_DEBUG(x) \
Yingdi Yua585d4d2014-09-20 21:55:47 -070066 std::clog << boost::get_system_time() << " " << boost::this_thread::get_id() << \
Yingdi Yuf7ede412014-08-30 20:37:52 -070067 " " << x << std::endl
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070068
Yingdi Yua585d4d2014-09-20 21:55:47 -070069#else // _DEBUG
70
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070071#define _LOG_DEBUG(x)
Yingdi Yua585d4d2014-09-20 21:55:47 -070072
73#endif // _DEBUG
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070074
75#endif // HAVE_LOG4CXX
76
Yingdi Yua585d4d2014-09-20 21:55:47 -070077#endif // CHRONOSYNC_LOGGER_HPP