blob: 2aa3344c3914ab884c2c8baf57a70cf9bc57e2f3 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 * Zhenkai Zhu
6 *
7 * BSD license, See the LICENSE file for more information
8 *
9 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
10 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
11 */
12
13#ifndef LOGGING_H
14#define LOGGING_H
15
16#include "config.h"
17
18#ifdef HAVE_LOG4CXX
19
20#include <log4cxx/logger.h>
21
22#define MEMBER_LOGGER \
23 static log4cxx::LoggerPtr staticModuleLogger;
24
25#define INIT_MEMBER_LOGGER(className,name) \
26 log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name);
27
28#define INIT_LOGGER(name) \
29 static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
30
31#define _LOG_DEBUG(x) \
32 LOG4CXX_DEBUG(staticModuleLogger, x);
33
34#define _LOG_TRACE(x) \
35 LOG4CXX_TRACE(staticModuleLogger, x);
36
37#define _LOG_FUNCTION(x) \
38 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
39
40#define _LOG_FUNCTION_NOARGS \
41 LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
42
43#define _LOG_ERROR(x) \
44 LOG4CXX_ERROR(staticModuleLogger, x);
45
46#define _LOG_ERROR_COND(cond,x) \
47 if (cond) { _LOG_ERROR(x) }
48
49#define _LOG_DEBUG_COND(cond,x) \
50 if (cond) { _LOG_DEBUG(x) }
51
52void
53INIT_LOGGERS ();
54
55#else // else HAVE_LOG4CXX
56
57#define INIT_LOGGER(name)
58#define _LOG_FUNCTION(x)
59#define _LOG_FUNCTION_NOARGS
60#define _LOG_TRACE(x)
61#define INIT_LOGGERS(x)
62#define _LOG_ERROR(x)
63#define _LOG_ERROR_COND(cond,x)
64#define _LOG_DEBUG_COND(cond,x)
65
66#define MEMBER_LOGGER
67#define INIT_MEMBER_LOGGER(className,name)
68
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 << std::endl;
77
78#else
79#define _LOG_DEBUG(x)
80#endif
81
82#endif // HAVE_LOG4CXX
83
84#endif // LOGGING_H