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 | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 30 | #define MEMBER_LOGGER \ |
| 31 | static log4cxx::LoggerPtr staticModuleLogger; |
| 32 | |
| 33 | #define INIT_MEMBER_LOGGER(className,name) \ |
| 34 | log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 35 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 36 | #define INIT_LOGGER(name) \ |
| 37 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 38 | |
| 39 | #define _LOG_DEBUG(x) \ |
| 40 | LOG4CXX_DEBUG(staticModuleLogger, x); |
| 41 | |
| 42 | #define _LOG_TRACE(x) \ |
| 43 | LOG4CXX_TRACE(staticModuleLogger, x); |
| 44 | |
| 45 | #define _LOG_FUNCTION(x) \ |
| 46 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")"); |
| 47 | |
| 48 | #define _LOG_FUNCTION_NOARGS \ |
| 49 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()"); |
| 50 | |
| 51 | #define _LOG_ERROR(x) \ |
| 52 | LOG4CXX_ERROR(staticModuleLogger, x); |
| 53 | |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 54 | #define _LOG_ERROR_COND(cond,x) \ |
| 55 | if (cond) { _LOG_ERROR(x) } |
| 56 | |
| 57 | #define _LOG_DEBUG_COND(cond,x) \ |
| 58 | if (cond) { _LOG_DEBUG(x) } |
| 59 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 60 | void |
| 61 | INIT_LOGGERS (); |
| 62 | |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 63 | #else // else HAVE_LOG4CXX |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 64 | |
| 65 | #define INIT_LOGGER(name) |
| 66 | #define _LOG_FUNCTION(x) |
| 67 | #define _LOG_FUNCTION_NOARGS |
| 68 | #define _LOG_TRACE(x) |
| 69 | #define INIT_LOGGERS(x) |
| 70 | #define _LOG_ERROR(x) |
Alexander Afanasyev | 49a30d0 | 2013-01-21 21:38:48 -0800 | [diff] [blame] | 71 | #define _LOG_ERROR_COND(cond,x) |
| 72 | #define _LOG_DEBUG_COND(cond,x) |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | 47cf2ef | 2013-01-28 15:13:47 -0800 | [diff] [blame] | 74 | #define MEMBER_LOGGER |
| 75 | #define INIT_MEMBER_LOGGER(className,name) |
| 76 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 77 | #ifdef _DEBUG |
| 78 | |
| 79 | #include <boost/thread/thread.hpp> |
| 80 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 81 | #include <iostream> |
| 82 | |
| 83 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | 02a86ec | 2013-03-04 13:09:31 -0800 | [diff] [blame] | 84 | std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << std::endl; |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 85 | |
| 86 | #else |
| 87 | #define _LOG_DEBUG(x) |
| 88 | #endif |
| 89 | |
| 90 | #endif // HAVE_LOG4CXX |
| 91 | |
| 92 | #endif // LOGGING_H |