A Discrete-Event Network Simulator
API
log-macros-enabled.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#ifndef NS3_LOG_MACROS_ENABLED_H
21#define NS3_LOG_MACROS_ENABLED_H
22
29// These two implementation macros
30// NS_LOG_APPEND_TIME_PREFIX_IMPL
31// NS_LOG_APPEND_NODE_PREFIX_IMPL
32// need to be defined in all configurations (debug, release, optimized)
33// for use by NS_FATAL_...
34
43#define NS_LOG_APPEND_TIME_PREFIX_IMPL \
44 do \
45 { \
46 ns3::TimePrinter printer = ns3::LogGetTimePrinter(); \
47 if (printer != 0) \
48 { \
49 (*printer)(std::clog); \
50 std::clog << " "; \
51 } \
52 } while (false)
53
62#define NS_LOG_APPEND_NODE_PREFIX_IMPL \
63 do \
64 { \
65 ns3::NodePrinter printer = ns3::LogGetNodePrinter(); \
66 if (printer != 0) \
67 { \
68 (*printer)(std::clog); \
69 std::clog << " "; \
70 } \
71 } while (false)
72
73#ifdef NS3_LOG_ENABLE
74
81#define NS_LOG_APPEND_TIME_PREFIX \
82 if (g_log.IsEnabled(ns3::LOG_PREFIX_TIME)) \
83 { \
84 NS_LOG_APPEND_TIME_PREFIX_IMPL; \
85 }
86
93#define NS_LOG_APPEND_NODE_PREFIX \
94 if (g_log.IsEnabled(ns3::LOG_PREFIX_NODE)) \
95 { \
96 NS_LOG_APPEND_NODE_PREFIX_IMPL; \
97 }
98
105#define NS_LOG_APPEND_FUNC_PREFIX \
106 if (g_log.IsEnabled(ns3::LOG_PREFIX_FUNC)) \
107 { \
108 std::clog << g_log.Name() << ":" << __FUNCTION__ << "(): "; \
109 }
110
117#define NS_LOG_APPEND_LEVEL_PREFIX(level) \
118 if (g_log.IsEnabled(ns3::LOG_PREFIX_LEVEL)) \
119 { \
120 std::clog << "[" << g_log.GetLevelLabel(level) << "] "; \
121 }
122
123#ifndef NS_LOG_APPEND_CONTEXT
141#define NS_LOG_APPEND_CONTEXT
142#endif /* NS_LOG_APPEND_CONTEXT */
143
144#ifndef NS_LOG_CONDITION
159#define NS_LOG_CONDITION
160#endif
161
181#define NS_LOG(level, msg) \
182 NS_LOG_CONDITION \
183 do \
184 { \
185 if (g_log.IsEnabled(level)) \
186 { \
187 NS_LOG_APPEND_TIME_PREFIX; \
188 NS_LOG_APPEND_NODE_PREFIX; \
189 NS_LOG_APPEND_CONTEXT; \
190 NS_LOG_APPEND_FUNC_PREFIX; \
191 NS_LOG_APPEND_LEVEL_PREFIX(level); \
192 std::clog << msg << std::endl; \
193 } \
194 } while (false)
195
204#define NS_LOG_FUNCTION_NOARGS() \
205 NS_LOG_CONDITION \
206 do \
207 { \
208 if (g_log.IsEnabled(ns3::LOG_FUNCTION)) \
209 { \
210 NS_LOG_APPEND_TIME_PREFIX; \
211 NS_LOG_APPEND_NODE_PREFIX; \
212 NS_LOG_APPEND_CONTEXT; \
213 std::clog << g_log.Name() << ":" << __FUNCTION__ << "()" << std::endl; \
214 } \
215 } while (false)
216
238#define NS_LOG_FUNCTION(parameters) \
239 NS_LOG_CONDITION \
240 do \
241 { \
242 if (g_log.IsEnabled(ns3::LOG_FUNCTION)) \
243 { \
244 NS_LOG_APPEND_TIME_PREFIX; \
245 NS_LOG_APPEND_NODE_PREFIX; \
246 NS_LOG_APPEND_CONTEXT; \
247 std::clog << g_log.Name() << ":" << __FUNCTION__ << "("; \
248 ns3::ParameterLogger(std::clog) << parameters; \
249 std::clog << ")" << std::endl; \
250 } \
251 } while (false)
252
260#define NS_LOG_UNCOND(msg) \
261 NS_LOG_CONDITION \
262 do \
263 { \
264 std::clog << msg << std::endl; \
265 } while (false)
266
267#endif /* NS3_LOG_ENABLE */
268
269#endif /* NS3_LOG_MACROS_ENABLED_H */