Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 8 | * 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 Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 12 | * 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 Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 16 | * 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 Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 24 | #ifndef CHRONOSYNC_LOGGER_HPP |
| 25 | #define CHRONOSYNC_LOGGER_HPP |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef HAVE_LOG4CXX |
| 28 | |
| 29 | #include <log4cxx/logger.h> |
| 30 | |
| 31 | #define INIT_LOGGER(name) \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 32 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 33 | |
| 34 | #define _LOG_DEBUG(x) \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 35 | LOG4CXX_DEBUG(staticModuleLogger, x) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 36 | |
| 37 | #define _LOG_TRACE(x) \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 38 | LOG4CXX_TRACE(staticModuleLogger, x) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 39 | |
| 40 | #define _LOG_FUNCTION(x) \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 41 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")") |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 42 | |
| 43 | #define _LOG_FUNCTION_NOARGS \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 44 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()") |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 45 | |
Zhenkai Zhu | 26cd6e3 | 2012-10-05 13:10:58 -0700 | [diff] [blame] | 46 | #define _LOG_ERROR(x) \ |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 47 | LOG4CXX_ERROR(staticModuleLogger, x) |
Zhenkai Zhu | 26cd6e3 | 2012-10-05 13:10:58 -0700 | [diff] [blame] | 48 | |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 49 | #else // HAVE_LOG4CXX |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 50 | |
| 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 Zhu | 26cd6e3 | 2012-10-05 13:10:58 -0700 | [diff] [blame] | 56 | #define _LOG_ERROR(x) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 57 | |
| 58 | #ifdef _DEBUG |
| 59 | |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 60 | #include <thread> |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 61 | #include <iostream> |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 62 | #include <ndn-cxx/util/time.hpp> |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 63 | |
| 64 | #define _LOG_DEBUG(x) \ |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 65 | std::clog << ndn::time::system_clock::now() << " " << std::this_thread::get_id() << \ |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 66 | " " << x << std::endl |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 67 | |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 68 | #else // _DEBUG |
| 69 | |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 70 | #define _LOG_DEBUG(x) |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 71 | |
| 72 | #endif // _DEBUG |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 73 | |
| 74 | #endif // HAVE_LOG4CXX |
| 75 | |
Yingdi Yu | a585d4d | 2014-09-20 21:55:47 -0700 | [diff] [blame] | 76 | #endif // CHRONOSYNC_LOGGER_HPP |