|
|
|
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 |
|
24 |
#ifdef NS3_LOG_ENABLE |
25 |
|
26 |
|
27 |
/** |
28 |
* \ingroup logging |
29 |
* Append the simulation time to a log message. |
30 |
* \internal |
31 |
* Logging implementation macro; should not be called directly. |
32 |
*/ |
33 |
#define NS_LOG_APPEND_TIME_PREFIX \ |
34 |
if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) \ |
35 |
{ \ |
36 |
ns3::LogTimePrinter printer = ns3::LogGetTimePrinter (); \ |
37 |
if (printer != 0) \ |
38 |
{ \ |
39 |
(*printer)(std::clog); \ |
40 |
std::clog << " "; \ |
41 |
} \ |
42 |
} |
43 |
|
44 |
/** |
45 |
* \ingroup logging |
46 |
* Append the simulation node id to a log message. |
47 |
* \internal |
48 |
* Logging implementation macro; should not be called directly. |
49 |
*/ |
50 |
#define NS_LOG_APPEND_NODE_PREFIX \ |
51 |
if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE)) \ |
52 |
{ \ |
53 |
ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); \ |
54 |
if (printer != 0) \ |
55 |
{ \ |
56 |
(*printer)(std::clog); \ |
57 |
std::clog << " "; \ |
58 |
} \ |
59 |
} |
60 |
|
61 |
/** |
62 |
* \ingroup logging |
63 |
* Append the function name to a log message. |
64 |
* \internal |
65 |
* Logging implementation macro; should not be called directly. |
66 |
*/ |
67 |
#define NS_LOG_APPEND_FUNC_PREFIX \ |
68 |
if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) \ |
69 |
{ \ |
70 |
std::clog << g_log.Name () << ":" << \ |
71 |
__FUNCTION__ << "(): "; \ |
72 |
} \ |
73 |
|
74 |
/** |
75 |
* \ingroup logging |
76 |
* Append the log severity level to a log message. |
77 |
* \internal |
78 |
* Logging implementation macro; should not be called directly. |
79 |
*/ |
80 |
#define NS_LOG_APPEND_LEVEL_PREFIX(level) \ |
81 |
if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL)) \ |
82 |
{ \ |
83 |
std::clog << "[" << g_log.GetLevelLabel (level) << "] "; \ |
84 |
} \ |
85 |
|
86 |
|
87 |
#ifndef NS_LOG_APPEND_CONTEXT |
88 |
/** |
89 |
* \ingroup logging |
90 |
* Append the node id to a log message. |
91 |
* |
92 |
* This is implemented locally in `.cc` files because |
93 |
* the the relevant variable is only known there. |
94 |
* |
95 |
* Preferred format is something like (assuming the node id is |
96 |
* accessible from `var`: |
97 |
* \code |
98 |
* if (var) |
99 |
* { |
100 |
* std::clog << "[node " << var->GetObject<Node> ()->GetId () << "] "; |
101 |
* } |
102 |
* \endcode |
103 |
* |
104 |
* \internal |
105 |
* Logging implementation macro; should not be called directly. |
106 |
* |
107 |
*/ |
108 |
#define NS_LOG_APPEND_CONTEXT |
109 |
#endif /* NS_LOG_APPEND_CONTEXT */ |
110 |
|
111 |
|
112 |
/** |
113 |
* \ingroup logging |
114 |
* |
115 |
* This macro allows you to log an arbitrary message at a specific |
116 |
* log level. |
117 |
* |
118 |
* The log message is expected to be a C++ ostream |
119 |
* message such as "my string" << aNumber << "my oth stream". |
120 |
* |
121 |
* Typical usage looks like: |
122 |
* \code |
123 |
* NS_LOG (LOG_DEBUG, "a number="<<aNumber<<", anotherNumber="<<anotherNumber); |
124 |
* \endcode |
125 |
* |
126 |
* \param level the log level |
127 |
* \param msg the message to log |
128 |
* \internal |
129 |
* Logging implementation macro; should not be called directly. |
130 |
*/ |
131 |
#define NS_LOG(level, msg) \ |
132 |
do \ |
133 |
{ \ |
134 |
if (g_log.IsEnabled (level)) \ |
135 |
{ \ |
136 |
NS_LOG_APPEND_TIME_PREFIX; \ |
137 |
NS_LOG_APPEND_NODE_PREFIX; \ |
138 |
NS_LOG_APPEND_CONTEXT; \ |
139 |
NS_LOG_APPEND_FUNC_PREFIX; \ |
140 |
NS_LOG_APPEND_LEVEL_PREFIX (level); \ |
141 |
std::clog << msg << std::endl; \ |
142 |
} \ |
143 |
} \ |
144 |
while (false) |
145 |
|
146 |
/** |
147 |
* \ingroup logging |
148 |
* |
149 |
* Output the name of the function. |
150 |
* |
151 |
* This should be used only in static functions; most member functions |
152 |
* should instead use NS_LOG_FUNCTION(). |
153 |
*/ |
154 |
#define NS_LOG_FUNCTION_NOARGS() \ |
155 |
do \ |
156 |
{ \ |
157 |
if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \ |
158 |
{ \ |
159 |
NS_LOG_APPEND_TIME_PREFIX; \ |
160 |
NS_LOG_APPEND_NODE_PREFIX; \ |
161 |
NS_LOG_APPEND_CONTEXT; \ |
162 |
std::clog << g_log.Name () << ":" \ |
163 |
<< __FUNCTION__ << "()" << std::endl; \ |
164 |
} \ |
165 |
} \ |
166 |
while (false) |
167 |
|
168 |
|
169 |
/** |
170 |
* \ingroup logging |
171 |
* |
172 |
* If log level LOG_FUNCTION is enabled, this macro will output |
173 |
* all input parameters separated by ", ". |
174 |
* |
175 |
* Typical usage looks like: |
176 |
* \code |
177 |
* NS_LOG_FUNCTION (aNumber<<anotherNumber); |
178 |
* \endcode |
179 |
* And the output will look like: |
180 |
* \code |
181 |
* Component:Function (aNumber, anotherNumber) |
182 |
* \endcode |
183 |
* |
184 |
* To facilitate function tracing, most functions should begin with |
185 |
* (at least) NS_LOG_FUNCTION(this). Static functions should use |
186 |
* NS_LOG_FUNCTION_NOARGS() instead. |
187 |
* |
188 |
* \param parameters the parameters to output. |
189 |
*/ |
190 |
#define NS_LOG_FUNCTION(parameters) \ |
191 |
do \ |
192 |
{ \ |
193 |
if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \ |
194 |
{ \ |
195 |
NS_LOG_APPEND_TIME_PREFIX; \ |
196 |
NS_LOG_APPEND_NODE_PREFIX; \ |
197 |
NS_LOG_APPEND_CONTEXT; \ |
198 |
std::clog << g_log.Name () << ":" \ |
199 |
<< __FUNCTION__ << "("; \ |
200 |
ns3::ParameterLogger (std::clog) << parameters; \ |
201 |
std::clog << ")" << std::endl; \ |
202 |
} \ |
203 |
} \ |
204 |
while (false) |
205 |
|
206 |
|
207 |
/** |
208 |
* \ingroup logging |
209 |
* |
210 |
* Output the requested message unconditionaly. |
211 |
* |
212 |
* \param msg the message to log |
213 |
*/ |
214 |
#define NS_LOG_UNCOND(msg) \ |
215 |
do \ |
216 |
{ \ |
217 |
std::clog << msg << std::endl; \ |
218 |
} \ |
219 |
while (false) |
220 |
|
221 |
|
222 |
#endif /* NS3_LOG_ENABLE */ |
223 |
|
224 |
#endif /* NS3_LOG_MACROS_ENABLED_H */ |