blob: 849d2e837a8dbb5799f43f6e139a1464ebfa043c [file] [log] [blame]
Alexander Afanasyevc507ac22013-01-21 16:01:58 -08001/* -*- 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#ifndef LOGGING_H
23#define LOGGING_H
24
25#include "config.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
46#define _LOG_ERROR(x) \
47 LOG4CXX_ERROR(staticModuleLogger, x);
48
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080049#define _LOG_ERROR_COND(cond,x) \
50 if (cond) { _LOG_ERROR(x) }
51
52#define _LOG_DEBUG_COND(cond,x) \
53 if (cond) { _LOG_DEBUG(x) }
54
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080055void
56INIT_LOGGERS ();
57
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080058#else // else HAVE_LOG4CXX
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080059
60#define INIT_LOGGER(name)
61#define _LOG_FUNCTION(x)
62#define _LOG_FUNCTION_NOARGS
63#define _LOG_TRACE(x)
64#define INIT_LOGGERS(x)
65#define _LOG_ERROR(x)
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080066#define _LOG_ERROR_COND(cond,x)
67#define _LOG_DEBUG_COND(cond,x)
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080068
69#ifdef _DEBUG
70
71#include <boost/thread/thread.hpp>
72#include <boost/date_time/posix_time/posix_time.hpp>
73#include <iostream>
74
75#define _LOG_DEBUG(x) \
76 std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << endl;
77
78#else
79#define _LOG_DEBUG(x)
80#endif
81
82#endif // HAVE_LOG4CXX
83
84#endif // LOGGING_H