A Discrete-Event Network Simulator
API
log-macros-enabled.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef NS3_LOG_MACROS_ENABLED_H
22 #define NS3_LOG_MACROS_ENABLED_H
23 
30 #ifdef NS3_LOG_ENABLE
31 
32 
39 #define NS_LOG_APPEND_TIME_PREFIX \
40  if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) \
41  { \
42  ns3::LogTimePrinter printer = ns3::LogGetTimePrinter (); \
43  if (printer != 0) \
44  { \
45  (*printer)(std::clog); \
46  std::clog << " "; \
47  } \
48  }
49 
56 #define NS_LOG_APPEND_NODE_PREFIX \
57  if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE)) \
58  { \
59  ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); \
60  if (printer != 0) \
61  { \
62  (*printer)(std::clog); \
63  std::clog << " "; \
64  } \
65  }
66 
73 #define NS_LOG_APPEND_FUNC_PREFIX \
74  if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) \
75  { \
76  std::clog << g_log.Name () << ":" << \
77  __FUNCTION__ << "(): "; \
78  } \
79 
80 
86 #define NS_LOG_APPEND_LEVEL_PREFIX(level) \
87  if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL)) \
88  { \
89  std::clog << "[" << g_log.GetLevelLabel (level) << "] "; \
90  } \
91 
92 
93 #ifndef NS_LOG_APPEND_CONTEXT
94 
111 #define NS_LOG_APPEND_CONTEXT
112 #endif /* NS_LOG_APPEND_CONTEXT */
113 
114 
115 #ifndef NS_LOG_CONDITION
116 
130 #define NS_LOG_CONDITION
131 #endif
132 
152 #define NS_LOG(level, msg) \
153  NS_LOG_CONDITION \
154  do \
155  { \
156  if (g_log.IsEnabled (level)) \
157  { \
158  NS_LOG_APPEND_TIME_PREFIX; \
159  NS_LOG_APPEND_NODE_PREFIX; \
160  NS_LOG_APPEND_CONTEXT; \
161  NS_LOG_APPEND_FUNC_PREFIX; \
162  NS_LOG_APPEND_LEVEL_PREFIX (level); \
163  std::clog << msg << std::endl; \
164  } \
165  } \
166  while (false)
167 
176 #define NS_LOG_FUNCTION_NOARGS() \
177  NS_LOG_CONDITION \
178  do \
179  { \
180  if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \
181  { \
182  NS_LOG_APPEND_TIME_PREFIX; \
183  NS_LOG_APPEND_NODE_PREFIX; \
184  NS_LOG_APPEND_CONTEXT; \
185  std::clog << g_log.Name () << ":" \
186  << __FUNCTION__ << "()" << std::endl; \
187  } \
188  } \
189  while (false)
190 
191 
213 #define NS_LOG_FUNCTION(parameters) \
214  NS_LOG_CONDITION \
215  do \
216  { \
217  if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \
218  { \
219  NS_LOG_APPEND_TIME_PREFIX; \
220  NS_LOG_APPEND_NODE_PREFIX; \
221  NS_LOG_APPEND_CONTEXT; \
222  std::clog << g_log.Name () << ":" \
223  << __FUNCTION__ << "("; \
224  ns3::ParameterLogger (std::clog) << parameters; \
225  std::clog << ")" << std::endl; \
226  } \
227  } \
228  while (false)
229 
230 
238 #define NS_LOG_UNCOND(msg) \
239  NS_LOG_CONDITION \
240  do \
241  { \
242  std::clog << msg << std::endl; \
243  } \
244  while (false)
245 
246 
247 #endif /* NS3_LOG_ENABLE */
248 
249 #endif /* NS3_LOG_MACROS_ENABLED_H */