View | Details | Raw Unified | Return to bug 1170
Collapse All | Expand All

(-)a/src/core/model/log-macros-disabled.h (+50 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2014 Andrey Mazo
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: Andrey Mazo <ahippo@yandex.com>
19
 */
20
21
#ifndef NS3_LOG_MACROS_DISABLED_H
22
#define NS3_LOG_MACROS_DISABLED_H
23
24
#ifndef NS3_LOG_ENABLE
25
26
#define NS_LOG_NOOP_INTERNAL(msg)           \
27
  do                                        \
28
    {                                       \
29
      if (false)                            \
30
        {                                   \
31
          std::clog << msg;                 \
32
        }                                   \
33
    }                                       \
34
  while (false)
35
36
#define NS_LOG(level, msg) \
37
        NS_LOG_NOOP_INTERNAL (msg)
38
39
#define NS_LOG_FUNCTION_NOARGS()
40
41
#define NS_LOG_FUNCTION(parameters) \
42
        NS_LOG_NOOP_INTERNAL (parameters)
43
44
#define NS_LOG_UNCOND(msg) \
45
        NS_LOG_NOOP_INTERNAL (msg)
46
47
48
#endif /* !NS3_LOG_ENABLE */
49
50
#endif /* NS3_LOG_MACROS_DISABLED_H */
(-)a/src/core/model/log-macros-enabled.h (+224 lines)
Line 0    Link Here 
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 */
(-)a/src/core/model/log.h (-209 / +3 lines)
 Lines 26-31    Link Here 
26
#include <stdint.h>
26
#include <stdint.h>
27
#include <map>
27
#include <map>
28
28
29
#include "log-macros-enabled.h"
30
#include "log-macros-disabled.h"
31
29
namespace ns3 {
32
namespace ns3 {
30
33
31
/**
34
/**
 Lines 182-308    Link Here 
182
185
183
/**
186
/**
184
 * \ingroup logging
187
 * \ingroup logging
185
 * Append the simulation time to a log message.
186
 * \internal
187
 * Logging implementation macro; should not be called directly.
188
 */
189
#define NS_LOG_APPEND_TIME_PREFIX                               \
190
  if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME))                   \
191
    {                                                           \
192
      ns3::LogTimePrinter printer = ns3::LogGetTimePrinter ();  \
193
      if (printer != 0)                                         \
194
        {                                                       \
195
          (*printer)(std::clog);                                \
196
          std::clog << " ";                                     \
197
        }                                                       \
198
    }
199
200
/**
201
 * \ingroup logging
202
 * Append the simulation node id to a log message.
203
 * \internal
204
 * Logging implementation macro; should not be called directly.
205
 */
206
#define NS_LOG_APPEND_NODE_PREFIX                               \
207
  if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE))                   \
208
    {                                                           \
209
      ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();  \
210
      if (printer != 0)                                         \
211
        {                                                       \
212
          (*printer)(std::clog);                                \
213
          std::clog << " ";                                     \
214
        }                                                       \
215
    }
216
217
/**
218
 * \ingroup logging
219
 * Append the function name to a log message.
220
 * \internal
221
 * Logging implementation macro; should not be called directly.
222
 */
223
#define NS_LOG_APPEND_FUNC_PREFIX                               \
224
  if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC))                   \
225
    {                                                           \
226
      std::clog << g_log.Name () << ":" <<                      \
227
      __FUNCTION__ << "(): ";                                   \
228
    }                                                           \
229
230
/**
231
 * \ingroup logging
232
 * Append the log severity level to a log message.
233
 * \internal
234
 * Logging implementation macro; should not be called directly.
235
 */
236
#define NS_LOG_APPEND_LEVEL_PREFIX(level)                       \
237
  if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL))                  \
238
    {                                                           \
239
      std::clog << "[" << g_log.GetLevelLabel (level) << "] ";  \
240
    }                                                           \
241
  
242
243
#ifndef NS_LOG_APPEND_CONTEXT
244
/**
245
 * \ingroup logging
246
 * Append the node id to a log message.
247
 *
248
 * This is implemented locally in `.cc` files because
249
 * the the relevant variable is only known there.
250
 *
251
 * Preferred format is something like (assuming the node id is
252
 * accessible from `var`:
253
 * \code
254
 *   if (var)
255
 *     {
256
 *       std::clog << "[node " << var->GetObject<Node> ()->GetId () << "] ";
257
 *     }
258
 * \endcode
259
 *
260
 * \internal
261
 * Logging implementation macro; should not be called directly.
262
 *
263
 */
264
#define NS_LOG_APPEND_CONTEXT
265
#endif /* NS_LOG_APPEND_CONTEXT */
266
267
268
#ifdef NS3_LOG_ENABLE
269
270
/**
271
 * \ingroup logging
272
 *
273
 * This macro allows you to log an arbitrary message at a specific
274
 * log level.
275
 *
276
 * The log message is expected to be a C++ ostream
277
 * message such as "my string" << aNumber << "my oth stream".
278
 *
279
 * Typical usage looks like:
280
 * \code
281
 * NS_LOG (LOG_DEBUG, "a number="<<aNumber<<", anotherNumber="<<anotherNumber);
282
 * \endcode
283
 *
284
 * \param level the log level
285
 * \param msg the message to log
286
 * \internal
287
 * Logging implementation macro; should not be called directly.
288
 */
289
#define NS_LOG(level, msg)                                      \
290
  do                                                            \
291
    {                                                           \
292
      if (g_log.IsEnabled (level))                              \
293
        {                                                       \
294
          NS_LOG_APPEND_TIME_PREFIX;                            \
295
          NS_LOG_APPEND_NODE_PREFIX;                            \
296
          NS_LOG_APPEND_CONTEXT;                                \
297
          NS_LOG_APPEND_FUNC_PREFIX;                            \
298
          NS_LOG_APPEND_LEVEL_PREFIX (level);                   \
299
          std::clog << msg << std::endl;                        \
300
        }                                                       \
301
    }                                                           \
302
  while (false)
303
304
/**
305
 * \ingroup logging
306
 *
188
 *
307
 * Use \ref NS_LOG to output a message of level LOG_ERROR.
189
 * Use \ref NS_LOG to output a message of level LOG_ERROR.
308
 *
190
 *
 Lines 344-410    Link Here 
344
/**
226
/**
345
 * \ingroup logging
227
 * \ingroup logging
346
 *
228
 *
347
 * Output the name of the function.
348
 *
349
 * This should be used only in static functions; most member functions
350
 * should instead use NS_LOG_FUNCTION().
351
 */
352
#define NS_LOG_FUNCTION_NOARGS()                                \
353
  do                                                            \
354
    {                                                           \
355
      if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
356
        {                                                       \
357
          NS_LOG_APPEND_TIME_PREFIX;                            \
358
          NS_LOG_APPEND_NODE_PREFIX;                            \
359
          NS_LOG_APPEND_CONTEXT;                                \
360
          std::clog << g_log.Name () << ":"                     \
361
                    << __FUNCTION__ << "()" << std::endl;       \
362
        }                                                       \
363
    }                                                           \
364
  while (false)
365
366
367
/**
368
 * \ingroup logging
369
 *
370
 * If log level LOG_FUNCTION is enabled, this macro will output
371
 * all input parameters separated by ", ".
372
 *
373
 * Typical usage looks like:
374
 * \code
375
 * NS_LOG_FUNCTION (aNumber<<anotherNumber);
376
 * \endcode
377
 * And the output will look like:
378
 * \code
379
 * Component:Function (aNumber, anotherNumber)
380
 * \endcode
381
 *
382
 * To facilitate function tracing, most functions should begin with
383
 * (at least) NS_LOG_FUNCTION(this).  Static functions should use
384
 * NS_LOG_FUNCTION_NOARGS() instead.
385
 *
386
 * \param parameters the parameters to output.
387
 */
388
#define NS_LOG_FUNCTION(parameters)                             \
389
  do                                                            \
390
    {                                                           \
391
      if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
392
        {                                                       \
393
          NS_LOG_APPEND_TIME_PREFIX;                            \
394
          NS_LOG_APPEND_NODE_PREFIX;                            \
395
          NS_LOG_APPEND_CONTEXT;                                \
396
          std::clog << g_log.Name () << ":"                     \
397
                    << __FUNCTION__ << "(";                     \
398
          ns3::ParameterLogger (std::clog) << parameters;       \
399
          std::clog << ")" << std::endl;                        \
400
        }                                                       \
401
    }                                                           \
402
  while (false)
403
404
405
/**
406
 * \ingroup logging
407
 *
408
 * Use \ref NS_LOG to output a message of level LOG_LOGIC
229
 * Use \ref NS_LOG to output a message of level LOG_LOGIC
409
 *
230
 *
410
 * \param msg the message to log
231
 * \param msg the message to log
 Lines 412-444    Link Here 
412
#define NS_LOG_LOGIC(msg) \
233
#define NS_LOG_LOGIC(msg) \
413
  NS_LOG (ns3::LOG_LOGIC, msg)
234
  NS_LOG (ns3::LOG_LOGIC, msg)
414
235
415
/**
416
 * \ingroup logging
417
 *
418
 * Output the requested message unconditionaly.
419
 *
420
 * \param msg the message to log
421
 */
422
#define NS_LOG_UNCOND(msg)              \
423
  do                                    \
424
    {                                   \
425
      std::clog << msg << std::endl;    \
426
    }                                   \
427
  while (false)
428
429
#else /* LOG_ENABLE */
430
431
#define NS_LOG(level, msg)
432
#define NS_LOG_ERROR(msg)
433
#define NS_LOG_WARN(msg)
434
#define NS_LOG_DEBUG(msg)
435
#define NS_LOG_INFO(msg)
436
#define NS_LOG_FUNCTION_NOARGS()
437
#define NS_LOG_FUNCTION(msg)
438
#define NS_LOG_LOGIC(msg)
439
#define NS_LOG_UNCOND(msg)
440
441
#endif /* LOG_ENABLE */
442
236
443
namespace ns3 {
237
namespace ns3 {
444
238
(-)a/src/core/wscript (+2 lines)
 Lines 248-253    Link Here 
248
        'model/ptr.h',
248
        'model/ptr.h',
249
        'model/object.h',
249
        'model/object.h',
250
        'model/log.h',
250
        'model/log.h',
251
        'model/log-macros-enabled.h',
252
        'model/log-macros-disabled.h',
251
        'model/assert.h',
253
        'model/assert.h',
252
        'model/breakpoint.h',
254
        'model/breakpoint.h',
253
        'model/fatal-error.h',
255
        'model/fatal-error.h',
(-)a/src/internet/test/tcp-test.cc (-3 / +1 lines)
 Lines 108-121    Link Here 
108
  return oss.str ();
108
  return oss.str ();
109
}
109
}
110
110
111
#ifdef NS3_LOG_ENABLE
111
static inline std::string GetString (Ptr<Packet> p)
112
static std::string GetString (Ptr<Packet> p)
113
{
112
{
114
  std::ostringstream oss;
113
  std::ostringstream oss;
115
  p->CopyData (&oss, p->GetSize ());
114
  p->CopyData (&oss, p->GetSize ());
116
  return oss.str ();
115
  return oss.str ();
117
}
116
}
118
#endif /* NS3_LOG_ENABLE */
119
117
120
TcpTestCase::TcpTestCase (uint32_t totalStreamSize,
118
TcpTestCase::TcpTestCase (uint32_t totalStreamSize,
121
                          uint32_t sourceWriteSize,
119
                          uint32_t sourceWriteSize,
(-)a/src/olsr/model/olsr-routing-protocol.cc (-2 lines)
 Lines 2456-2464    Link Here 
2456
2456
2457
  if (nb_tuple != NULL)
2457
  if (nb_tuple != NULL)
2458
    {
2458
    {
2459
#ifdef NS3_LOG_ENABLE
2460
      int statusBefore = nb_tuple->status;
2459
      int statusBefore = nb_tuple->status;
2461
#endif // NS3_LOG_ENABLE
2462
2460
2463
      bool hasSymmetricLink = false;
2461
      bool hasSymmetricLink = false;
2464
2462

Return to bug 1170