blob: 975153d67c0abcf40e731982106a295fa6a9784d [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
Alexander Afanasyev47cf2ef2013-01-28 15:13:47 -080031#define MEMBER_LOGGER \
32 static log4cxx::LoggerPtr staticModuleLogger;
33
34#define INIT_MEMBER_LOGGER(className,name) \
35 log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name);
36
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080037#define INIT_LOGGER(name) \
38 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
39
40#define _LOG_DEBUG(x) \
41 LOG4CXX_DEBUG(staticModuleLogger, x);
42
43#define _LOG_TRACE(x) \
44 LOG4CXX_TRACE(staticModuleLogger, x);
45
46#define _LOG_FUNCTION(x) \
47 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
48
49#define _LOG_FUNCTION_NOARGS \
50 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
51
52#define _LOG_ERROR(x) \
53 LOG4CXX_ERROR(staticModuleLogger, x);
54
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080055#define _LOG_ERROR_COND(cond,x) \
56 if (cond) { _LOG_ERROR(x) }
57
58#define _LOG_DEBUG_COND(cond,x) \
59 if (cond) { _LOG_DEBUG(x) }
60
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080061void
62INIT_LOGGERS ();
63
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080064#else // else HAVE_LOG4CXX
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080065
66#define INIT_LOGGER(name)
67#define _LOG_FUNCTION(x)
68#define _LOG_FUNCTION_NOARGS
69#define _LOG_TRACE(x)
70#define INIT_LOGGERS(x)
71#define _LOG_ERROR(x)
Alexander Afanasyev49a30d02013-01-21 21:38:48 -080072#define _LOG_ERROR_COND(cond,x)
73#define _LOG_DEBUG_COND(cond,x)
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080074
Alexander Afanasyev47cf2ef2013-01-28 15:13:47 -080075#define MEMBER_LOGGER
76#define INIT_MEMBER_LOGGER(className,name)
77
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080078#ifdef _DEBUG
79
80#include <boost/thread/thread.hpp>
81#include <boost/date_time/posix_time/posix_time.hpp>
82#include <iostream>
83
84#define _LOG_DEBUG(x) \
Alexander Afanasyev02a86ec2013-03-04 13:09:31 -080085 std::clog << boost::get_system_time () << " " << boost::this_thread::get_id () << " " << x << std::endl;
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080086
87#else
88#define _LOG_DEBUG(x)
89#endif
90
91#endif // HAVE_LOG4CXX
92
93#endif // LOGGING_H