blob: 9da0dc840d702a6a8b9ded543a97eb185a701010 [file] [log] [blame]
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07001/* -*- 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 Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_LOG_H
24#define SYNC_LOG_H
25
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070026#ifdef NS3_MODULE
27
28#include <ns3/log.h>
29
Alexander Afanasyev0ac399e2012-04-27 13:28:28 -070030#ifdef _DEBUG
31
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070032#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 Afanasyev0ac399e2012-04-27 13:28:28 -070046#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 Afanasyev4f9ea482012-03-15 11:57:29 -070057#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 Afanasyev181d7e52012-04-09 13:54:11 -070064#define _LOG_INFO(x) \
65 LOG4CXX_INFO(staticModuleLogger, x);
66
67#define _LOG_DEBUG(x) \
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070068 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
79void
80INIT_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 Afanasyev181d7e52012-04-09 13:54:11 -070088#define _LOG_INFO(x)
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070089#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 Afanasyev181d7e52012-04-09 13:54:11 -0700106#endif // NS3_MODULE
107
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700108#endif // SYNC_LOG_H