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 | |
| 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 Zhu | 26cd6e3 | 2012-10-05 13:10:58 -0700 | [diff] [blame] | 46 | #define _LOG_ERROR(x) \ |
| 47 | LOG4CXX_ERROR(staticModuleLogger, x); |
| 48 | |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 49 | void |
| 50 | INIT_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 Zhu | 26cd6e3 | 2012-10-05 13:10:58 -0700 | [diff] [blame] | 59 | #define _LOG_ERROR(x) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 60 | |
| 61 | #ifdef _DEBUG |
| 62 | |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 63 | #include <boost/date_time/posix_time/posix_time.hpp> |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame^] | 64 | #include <boost/thread/thread_time.hpp> |
| 65 | #include <boost/thread/thread.hpp> |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 66 | #include <iostream> |
| 67 | |
| 68 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame^] | 69 | std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << std::endl; |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 70 | |
| 71 | #else |
| 72 | #define _LOG_DEBUG(x) |
| 73 | #endif |
| 74 | |
| 75 | #endif // HAVE_LOG4CXX |
| 76 | |
| 77 | #endif // SYNC_LOG_H |