Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
Chaoyi Bian | 3e1eb16 | 2012-04-03 16:59:32 -0700 | [diff] [blame] | 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_LOG_H |
| 24 | #define SYNC_LOG_H |
| 25 | |
Alexander Afanasyev | 181d7e5 | 2012-04-09 13:54:11 -0700 | [diff] [blame] | 26 | #ifdef NS3_MODULE |
| 27 | |
| 28 | #include <ns3/log.h> |
| 29 | |
Alexander Afanasyev | 0ac399e | 2012-04-27 13:28:28 -0700 | [diff] [blame] | 30 | #ifdef _DEBUG |
| 31 | |
Alexander Afanasyev | 181d7e5 | 2012-04-09 13:54:11 -0700 | [diff] [blame] | 32 | #define INIT_LOGGER(name) NS_LOG_COMPONENT_DEFINE(name); |
| 33 | |
| 34 | #define _LOG_INFO(x) NS_LOG_INFO(x) |
| 35 | |
| 36 | #define _LOG_DEBUG(x) NS_LOG_DEBUG(x) |
| 37 | |
| 38 | #define _LOG_TRACE(x) NS_LOG_LOGIC(x) |
| 39 | |
| 40 | #define _LOG_FUNCTION(x) NS_LOG_FUNCTION(x) |
| 41 | |
| 42 | #define _LOG_FUNCTION_NOARGS NS_LOG_FUNCTION_NOARGS |
| 43 | |
| 44 | #else |
| 45 | |
Alexander Afanasyev | 0ac399e | 2012-04-27 13:28:28 -0700 | [diff] [blame] | 46 | #define INIT_LOGGER(name) |
| 47 | #define _LOG_INFO(x) |
| 48 | #define _LOG_DEBUG(x) |
| 49 | #define _LOG_TRACE(x) |
| 50 | #define _LOG_FUNCTION(x) |
| 51 | #define _LOG_FUNCTION_NOARGS |
| 52 | |
| 53 | #endif |
| 54 | |
| 55 | #else |
| 56 | |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 57 | #ifdef HAVE_LOG4CXX |
| 58 | |
| 59 | #include <log4cxx/logger.h> |
| 60 | |
| 61 | #define INIT_LOGGER(name) \ |
| 62 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 63 | |
Alexander Afanasyev | 181d7e5 | 2012-04-09 13:54:11 -0700 | [diff] [blame] | 64 | #define _LOG_INFO(x) \ |
| 65 | LOG4CXX_INFO(staticModuleLogger, x); |
| 66 | |
| 67 | #define _LOG_DEBUG(x) \ |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 68 | LOG4CXX_DEBUG(staticModuleLogger, x); |
| 69 | |
| 70 | #define _LOG_TRACE(x) \ |
| 71 | LOG4CXX_TRACE(staticModuleLogger, x); |
| 72 | |
| 73 | #define _LOG_FUNCTION(x) \ |
| 74 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")"); |
| 75 | |
| 76 | #define _LOG_FUNCTION_NOARGS \ |
| 77 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()"); |
| 78 | |
| 79 | void |
| 80 | INIT_LOGGERS (); |
| 81 | |
| 82 | #else |
| 83 | |
| 84 | #define INIT_LOGGER(name) |
| 85 | #define _LOG_FUNCTION(x) |
| 86 | #define _LOG_FUNCTION_NOARGS |
| 87 | #define _LOG_TRACE(x) |
Alexander Afanasyev | 181d7e5 | 2012-04-09 13:54:11 -0700 | [diff] [blame] | 88 | #define _LOG_INFO(x) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 89 | #define INIT_LOGGERS(x) |
| 90 | |
| 91 | #ifdef _DEBUG |
| 92 | |
| 93 | #include <boost/thread/thread.hpp> |
| 94 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 95 | #include <iostream> |
| 96 | |
| 97 | #define _LOG_DEBUG(x) \ |
| 98 | std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << endl; |
| 99 | |
| 100 | #else |
| 101 | #define _LOG_DEBUG(x) |
| 102 | #endif |
| 103 | |
| 104 | #endif // HAVE_LOG4CXX |
| 105 | |
Alexander Afanasyev | 181d7e5 | 2012-04-09 13:54:11 -0700 | [diff] [blame] | 106 | #endif // NS3_MODULE |
| 107 | |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 108 | #endif // SYNC_LOG_H |