blob: f7c66f0b85e123ebb0c1152dfa35f6dce9e48cec [file] [log] [blame]
Chengyu Fan71b712b2015-09-09 22:13:56 -06001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2015 University of California, Los Angeles,
4 * 2015 Colorado State University
5 *
6 * This file is part of ChronoSync, synchronization library for distributed realtime
7 * applications for NDN.
8 *
9 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation, either
11 * version 3 of the License, or (at your option) any later version.
12 *
13 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
21 * @author Chaoyi Bian <bcy@pku.edu.cn>
22 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
23 * @author Chengyu Fan <chengyu@cs.colostate.edu>
24 */
25
26#ifndef ATMOS_CATALOG_LOGGER_HPP
27#define ATMOS_CATALOG_LOGGER_HPP
28
29#ifdef HAVE_LOG4CXX
30
31#include <log4cxx/logger.h>
32#include <log4cxx/propertyconfigurator.h>
33
34#define INIT_LOGGER(name) \
35 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
36
Chengyu Fancfb80c72015-10-19 16:50:04 -060037#define _LOG_INFO(x) \
38 LOG4CXX_INFO(staticModuleLogger, x)
39
Chengyu Fan71b712b2015-09-09 22:13:56 -060040#define _LOG_DEBUG(x) \
41 LOG4CXX_DEBUG(staticModuleLogger, x)
42
43#define _LOG_TRACE(x) \
44 LOG4CXX_TRACE(staticModuleLogger, x)
45
46#define _LOG_FUNCTION(x) \
47 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")")
48
49#define _LOG_FUNCTION_NOARGS \
50 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()")
51
52#define _LOG_ERROR(x) \
53 LOG4CXX_ERROR(staticModuleLogger, x)
54
Chengyu Fancfb80c72015-10-19 16:50:04 -060055#define _LOG_FATAL(x) \
56 LOG4CXX_FATAL(staticModuleLogger, x)
57
Chengyu Fan71b712b2015-09-09 22:13:56 -060058#else // HAVE_LOG4CXX
59
60#define INIT_LOGGER(name)
61#define _LOG_FUNCTION(x)
62#define _LOG_FUNCTION_NOARGS
63#define _LOG_TRACE(x)
64#define INIT_LOGGERS(x)
Chengyu Fancfb80c72015-10-19 16:50:04 -060065#define _LOG_ERROR(x) \
66 std::cerr << x << std::endl
Chengyu Fan71b712b2015-09-09 22:13:56 -060067
68#ifdef _DEBUG
69
70#include <thread>
71#include <iostream>
72#include <ndn-cxx/util/time.hpp>
73
74// to print out messages, must be in debug mode
Chengyu Fancfb80c72015-10-19 16:50:04 -060075
Chengyu Fan71b712b2015-09-09 22:13:56 -060076#define _LOG_DEBUG(x) \
Chengyu Fancfb80c72015-10-19 16:50:04 -060077 std::clog << ndn::time::system_clock::now() << " " << x << std::endl
78
79#define _LOG_FATAL(x) \
80 std::clog << ndn::time::system_clock::now() << " " << x << std::endl
81
Chengyu Fan71b712b2015-09-09 22:13:56 -060082
83#else // _DEBUG
84
85#define _LOG_DEBUG(x)
Chengyu Fancfb80c72015-10-19 16:50:04 -060086#define _LOG_FATAL(x)
Chengyu Fan71b712b2015-09-09 22:13:56 -060087
88#endif // _DEBUG
89
90#endif // HAVE_LOG4CXX
91
92#endif // ATMOS_CATALOG_LOGGER_HPP