A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  auto flags = std::clog.setf(std::ios_base::boolalpha); \
193  std::clog << msg << std::endl; \
194  std::clog.flags(flags); \
195  } \
196  } while (false)
197 
206 #define NS_LOG_FUNCTION_NOARGS() \
207  NS_LOG_CONDITION \
208  do \
209  { \
210  if (g_log.IsEnabled(ns3::LOG_FUNCTION)) \
211  { \
212  NS_LOG_APPEND_TIME_PREFIX; \
213  NS_LOG_APPEND_NODE_PREFIX; \
214  NS_LOG_APPEND_CONTEXT; \
215  std::clog << g_log.Name() << ":" << __FUNCTION__ << "()" << std::endl; \
216  } \
217  } while (false)
218 
240 #define NS_LOG_FUNCTION(parameters) \
241  NS_LOG_CONDITION \
242  do \
243  { \
244  if (g_log.IsEnabled(ns3::LOG_FUNCTION)) \
245  { \
246  NS_LOG_APPEND_TIME_PREFIX; \
247  NS_LOG_APPEND_NODE_PREFIX; \
248  NS_LOG_APPEND_CONTEXT; \
249  std::clog << g_log.Name() << ":" << __FUNCTION__ << "("; \
250  auto flags = std::clog.setf(std::ios_base::boolalpha); \
251  ns3::ParameterLogger(std::clog) << parameters; \
252  std::clog.flags(flags); \
253  std::clog << ")" << std::endl; \
254  } \
255  } while (false)
256 
264 #define NS_LOG_UNCOND(msg) \
265  NS_LOG_CONDITION \
266  do \
267  { \
268  auto flags = std::clog.setf(std::ios_base::boolalpha); \
269  std::clog << msg << std::endl; \
270  std::clog.flags(flags); \
271  } while (false)
272 
273 #endif /* NS3_LOG_ENABLE */
274 
275 #endif /* NS3_LOG_MACROS_ENABLED_H */