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> |
| 19 | * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_LOG_H |
| 24 | #define SYNC_LOG_H |
| 25 | |
| 26 | #ifdef HAVE_LOG4CXX |
| 27 | |
| 28 | #include <log4cxx/logger.h> |
| 29 | |
| 30 | #define INIT_LOGGER(name) \ |
| 31 | static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name); |
| 32 | |
| 33 | #define _LOG_DEBUG(x) \ |
| 34 | LOG4CXX_DEBUG(staticModuleLogger, x); |
| 35 | |
| 36 | #define _LOG_TRACE(x) \ |
| 37 | LOG4CXX_TRACE(staticModuleLogger, x); |
| 38 | |
| 39 | #define _LOG_FUNCTION(x) \ |
| 40 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")"); |
| 41 | |
| 42 | #define _LOG_FUNCTION_NOARGS \ |
| 43 | LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()"); |
| 44 | |
| 45 | void |
| 46 | INIT_LOGGERS (); |
| 47 | |
| 48 | #else |
| 49 | |
| 50 | #define INIT_LOGGER(name) |
| 51 | #define _LOG_FUNCTION(x) |
| 52 | #define _LOG_FUNCTION_NOARGS |
| 53 | #define _LOG_TRACE(x) |
| 54 | #define INIT_LOGGERS(x) |
| 55 | |
| 56 | #ifdef _DEBUG |
| 57 | |
| 58 | #include <boost/thread/thread.hpp> |
| 59 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 60 | #include <iostream> |
| 61 | |
| 62 | #define _LOG_DEBUG(x) \ |
| 63 | std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << endl; |
| 64 | |
| 65 | #else |
| 66 | #define _LOG_DEBUG(x) |
| 67 | #endif |
| 68 | |
| 69 | #endif // HAVE_LOG4CXX |
| 70 | |
| 71 | #endif // SYNC_LOG_H |