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 
31 // These two implementation macros
32 // NS_LOG_APPEND_TIME_PREFIX_IMPL
33 // NS_LOG_APPEND_NODE_PREFIX_IMPL
34 // need to be defined in all configurations (debug, release, optimized)
35 // for use by NS_FATAL_...
36 
45 #define NS_LOG_APPEND_TIME_PREFIX_IMPL \
46  do { \
47  ns3::TimePrinter printer = ns3::LogGetTimePrinter (); \
48  if (printer != 0) \
49  { \
50  (*printer)(std::clog); \
51  std::clog << " "; \
52  } \
53  } while (false)
54 
63 #define NS_LOG_APPEND_NODE_PREFIX_IMPL \
64  do { \
65  ns3::NodePrinter printer = ns3::LogGetNodePrinter (); \
66  if (printer != 0) \
67  { \
68  (*printer)(std::clog); \
69  std::clog << " "; \
70  } \
71  } while (false)
72 
73 
74 
75 
76 #ifdef NS3_LOG_ENABLE
77 
84 #define NS_LOG_APPEND_TIME_PREFIX \
85  if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) \
86  { \
87  NS_LOG_APPEND_TIME_PREFIX_IMPL; \
88  }
89 
96 #define NS_LOG_APPEND_NODE_PREFIX \
97  if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE)) \
98  { \
99  NS_LOG_APPEND_NODE_PREFIX_IMPL; \
100  }
101 
108 #define NS_LOG_APPEND_FUNC_PREFIX \
109  if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) \
110  { \
111  std::clog << g_log.Name () << ":" \
112  << __FUNCTION__ << "(): "; \
113  } \
114 
121 #define NS_LOG_APPEND_LEVEL_PREFIX(level) \
122  if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL)) \
123  { \
124  std::clog << "[" << g_log.GetLevelLabel (level) << "] "; \
125  } \
126 
127 
128 #ifndef NS_LOG_APPEND_CONTEXT
146 #define NS_LOG_APPEND_CONTEXT
147 #endif /* NS_LOG_APPEND_CONTEXT */
148 
149 
150 #ifndef NS_LOG_CONDITION
165 #define NS_LOG_CONDITION
166 #endif
167 
187 #define NS_LOG(level, msg) \
188  NS_LOG_CONDITION \
189  do { \
190  if (g_log.IsEnabled (level)) \
191  { \
192  NS_LOG_APPEND_TIME_PREFIX; \
193  NS_LOG_APPEND_NODE_PREFIX; \
194  NS_LOG_APPEND_CONTEXT; \
195  NS_LOG_APPEND_FUNC_PREFIX; \
196  NS_LOG_APPEND_LEVEL_PREFIX (level); \
197  std::clog << msg << std::endl; \
198  } \
199  } while (false)
200 
209 #define NS_LOG_FUNCTION_NOARGS() \
210  NS_LOG_CONDITION \
211  do { \
212  if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \
213  { \
214  NS_LOG_APPEND_TIME_PREFIX; \
215  NS_LOG_APPEND_NODE_PREFIX; \
216  NS_LOG_APPEND_CONTEXT; \
217  std::clog << g_log.Name () << ":" \
218  << __FUNCTION__ << "()" << std::endl; \
219  } \
220  } while (false)
221 
222 
244 #define NS_LOG_FUNCTION(parameters) \
245  NS_LOG_CONDITION \
246  do \
247  { \
248  if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \
249  { \
250  NS_LOG_APPEND_TIME_PREFIX; \
251  NS_LOG_APPEND_NODE_PREFIX; \
252  NS_LOG_APPEND_CONTEXT; \
253  std::clog << g_log.Name () << ":" \
254  << __FUNCTION__ << "("; \
255  ns3::ParameterLogger (std::clog) << parameters; \
256  std::clog << ")" << std::endl; \
257  } \
258  } \
259  while (false)
260 
261 
269 #define NS_LOG_UNCOND(msg) \
270  NS_LOG_CONDITION \
271  do { \
272  std::clog << msg << std::endl; \
273  } while (false)
274 
275 
276 #endif /* NS3_LOG_ENABLE */
277 
278 #endif /* NS3_LOG_MACROS_ENABLED_H */