blob: 3d2f5d33321d992af03ece9c593ce33e155911a9 [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
24#ifndef SYNC_LOG_H
25#define SYNC_LOG_H
26
27#ifdef HAVE_LOG4CXX
28
29#include <log4cxx/logger.h>
30
31#define INIT_LOGGER(name) \
32 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
33
34#define _LOG_DEBUG(x) \
35 LOG4CXX_DEBUG(staticModuleLogger, x);
36
37#define _LOG_TRACE(x) \
38 LOG4CXX_TRACE(staticModuleLogger, x);
39
40#define _LOG_FUNCTION(x) \
41 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
42
43#define _LOG_FUNCTION_NOARGS \
44 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
45
Zhenkai Zhu26cd6e32012-10-05 13:10:58 -070046#define _LOG_ERROR(x) \
47 LOG4CXX_ERROR(staticModuleLogger, x);
48
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070049void
50INIT_LOGGERS ();
51
52#else
53
54#define INIT_LOGGER(name)
55#define _LOG_FUNCTION(x)
56#define _LOG_FUNCTION_NOARGS
57#define _LOG_TRACE(x)
58#define INIT_LOGGERS(x)
Zhenkai Zhu26cd6e32012-10-05 13:10:58 -070059#define _LOG_ERROR(x)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070060
61#ifdef _DEBUG
62
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070063#include <boost/date_time/posix_time/posix_time.hpp>
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070064#include <boost/thread/thread_time.hpp>
65#include <boost/thread/thread.hpp>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070066#include <iostream>
67
68#define _LOG_DEBUG(x) \
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070069 std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << std::endl;
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070070
71#else
72#define _LOG_DEBUG(x)
73#endif
74
75#endif // HAVE_LOG4CXX
76
77#endif // SYNC_LOG_H