Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef LOGGING_H |
| 22 | #define LOGGING_H |
| 23 | |
Alexander Afanasyev | e83c056 | 2016-12-24 10:20:41 -0800 | [diff] [blame] | 24 | #include "core/chronoshare-config.hpp" |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 25 | |
| 26 | #ifdef HAVE_LOG4CXX |
| 27 | |
| 28 | #include <log4cxx/logger.h> |
| 29 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 30 | #define MEMBER_LOGGER static log4cxx::LoggerPtr staticModuleLogger; |
Alexander Afanasyev | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 32 | #define INIT_MEMBER_LOGGER(className, name) \ |
| 33 | log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name); |
Alexander Afanasyev | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 34 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 35 | #define INIT_LOGGER(name) \ |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 36 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 38 | #define _LOG_DEBUG(x) LOG4CXX_DEBUG(staticModuleLogger, x); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 40 | #define _LOG_TRACE(x) LOG4CXX_TRACE(staticModuleLogger, x); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 42 | #define _LOG_FUNCTION(x) LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")"); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 44 | #define _LOG_FUNCTION_NOARGS LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()"); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 46 | #define _LOG_ERROR(x) LOG4CXX_ERROR(staticModuleLogger, x); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 48 | #define _LOG_ERROR_COND(cond, x) \ |
| 49 | if (cond) { \ |
| 50 | _LOG_ERROR(x) \ |
| 51 | } |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 53 | #define _LOG_DEBUG_COND(cond, x) \ |
| 54 | if (cond) { \ |
| 55 | _LOG_DEBUG(x) \ |
| 56 | } |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 58 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 59 | INIT_LOGGERS(); |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 61 | #else // else HAVE_LOG4CXX |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 62 | |
| 63 | #define INIT_LOGGER(name) |
| 64 | #define _LOG_FUNCTION(x) |
| 65 | #define _LOG_FUNCTION_NOARGS |
| 66 | #define _LOG_TRACE(x) |
| 67 | #define INIT_LOGGERS(x) |
| 68 | #define _LOG_ERROR(x) |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 69 | #define _LOG_ERROR_COND(cond, x) |
| 70 | #define _LOG_DEBUG_COND(cond, x) |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 72 | #define MEMBER_LOGGER |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 73 | #define INIT_MEMBER_LOGGER(className, name) |
Alexander Afanasyev | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 75 | #ifdef _DEBUG |
| 76 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 77 | #include <boost/date_time/posix_time/posix_time.hpp> |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 78 | #include <boost/thread/thread.hpp> |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 79 | #include <iostream> |
| 80 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 81 | #define _LOG_DEBUG(x) \ |
| 82 | std::clog << boost::get_system_time() << " " << boost::this_thread::get_id() << " " << x \ |
| 83 | << std::endl; |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 84 | |
| 85 | #else |
| 86 | #define _LOG_DEBUG(x) |
| 87 | #endif |
| 88 | |
| 89 | #endif // HAVE_LOG4CXX |
| 90 | |
| 91 | #endif // LOGGING_H |