A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
log.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_H
22 #define NS3_LOG_H
23 
24 #include <string>
25 #include <iostream>
26 #include <stdint.h>
27 #include <map>
28 
29 #include "log-macros-enabled.h"
30 #include "log-macros-disabled.h"
31 
32 namespace ns3 {
33 
71 enum LogLevel {
72  LOG_NONE = 0x00000000,
73 
74  LOG_ERROR = 0x00000001,
75  LOG_LEVEL_ERROR = 0x00000001,
76 
77  LOG_WARN = 0x00000002,
78  LOG_LEVEL_WARN = 0x00000003,
79 
80  LOG_DEBUG = 0x00000004,
81  LOG_LEVEL_DEBUG = 0x00000007,
82 
83  LOG_INFO = 0x00000008,
84  LOG_LEVEL_INFO = 0x0000000f,
85 
86  LOG_FUNCTION = 0x00000010,
87  LOG_LEVEL_FUNCTION = 0x0000001f,
88 
89  LOG_LOGIC = 0x00000020,
90  LOG_LEVEL_LOGIC = 0x0000003f,
91 
92  LOG_ALL = 0x0fffffff,
94 
95  LOG_PREFIX_FUNC = 0x80000000,
96  LOG_PREFIX_TIME = 0x40000000,
97  LOG_PREFIX_NODE = 0x20000000,
98  LOG_PREFIX_LEVEL = 0x10000000,
99  LOG_PREFIX_ALL = 0xf0000000
100 };
101 
116 void LogComponentEnable (char const *name, enum LogLevel level);
117 
128 void LogComponentEnableAll (enum LogLevel level);
129 
130 
142 void LogComponentDisable (char const *name, enum LogLevel level);
143 
151 void LogComponentDisableAll (enum LogLevel level);
152 
153 
154 } // namespace ns3
155 
170 #define NS_LOG_COMPONENT_DEFINE(name) \
171  static ns3::LogComponent g_log = ns3::LogComponent (name)
172 
183 #define NS_LOG_COMPONENT_DEFINE_MASK(name, mask) \
184  static ns3::LogComponent g_log = ns3::LogComponent (name, mask)
185 
193 #define NS_LOG_ERROR(msg) \
194  NS_LOG (ns3::LOG_ERROR, msg)
195 
203 #define NS_LOG_WARN(msg) \
204  NS_LOG (ns3::LOG_WARN, msg)
205 
213 #define NS_LOG_DEBUG(msg) \
214  NS_LOG (ns3::LOG_DEBUG, msg)
215 
223 #define NS_LOG_INFO(msg) \
224  NS_LOG (ns3::LOG_INFO, msg)
225 
233 #define NS_LOG_LOGIC(msg) \
234  NS_LOG (ns3::LOG_LOGIC, msg)
235 
236 
237 namespace ns3 {
238 
246 void LogComponentPrintList (void);
247 
248 typedef void (*LogTimePrinter)(std::ostream &os);
249 typedef void (*LogNodePrinter)(std::ostream &os);
250 
253 
256 
257 
264 {
265 public:
274  LogComponent (const std::string & name, const enum LogLevel mask = LOG_NONE);
281  bool IsEnabled (const enum LogLevel level) const;
287  bool IsNoneEnabled (void) const;
293  void Enable (const enum LogLevel level);
299  void Disable (const enum LogLevel level);
305  char const *Name (void) const;
312  static std::string GetLevelLabel(const enum LogLevel level);
318  void SetMask (const enum LogLevel level);
319 private:
324  void EnvVarCheck (void);
325 
326  int32_t m_levels;
327  int32_t m_mask;
328  std::string m_name;
329 
330 }; // class LogComponent
331 
338 {
339  bool m_first;
340  std::ostream &m_os;
341 public:
347  ParameterLogger (std::ostream &os);
348 
355  template<typename T>
357  {
358  if (m_first)
359  {
360  m_os << param;
361  m_first = false;
362  }
363  else
364  {
365  m_os << ", " << param;
366  }
367  return *this;
368  }
369 };
370 
371 } // namespace ns3
372 
373 
374 #endif /* NS3_LOG_H */
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:342
void LogComponentDisableAll(enum LogLevel level)
Disable all logging for all components.
Definition: log.cc:370
void LogSetNodePrinter(LogNodePrinter printer)
Definition: log.cc:579
std::ostream & m_os
Underlying output stream.
Definition: log.h:340
no logging
Definition: log.h:72
ParameterLogger & operator<<(T param)
Write a function parameter on the output stream, separating paramters after the first by ...
Definition: log.h:356
bool m_first
First argument flag, doesn't get ,.
Definition: log.h:339
A single log component configuration.
Definition: log.h:263
ParameterLogger(std::ostream &os)
Constructor.
Definition: log.cc:589
void Disable(const enum LogLevel level)
Disable logging at level for this LogComponent.
Definition: log.cc:270
void EnvVarCheck(void)
Parse the NS_LOG environment variable for options relating to this LogComponent.
Definition: log.cc:107
void LogSetTimePrinter(LogTimePrinter printer)
Definition: log.cc:565
rare ad-hoc debug messages
Definition: log.h:80
control flow tracing within functions
Definition: log.h:89
Insert , when streaming function arguments.
Definition: log.h:337
serious error messages only
Definition: log.h:74
void Enable(const enum LogLevel level)
Enable this LogComponent at level
Definition: log.cc:264
bool IsEnabled(const enum LogLevel level) const
Check if this LogComponent is enabled for level
Definition: log.cc:245
void SetMask(const enum LogLevel level)
Prevent the enabling of a specific LogLevel.
Definition: log.cc:258
LogNodePrinter LogGetNodePrinter(void)
Definition: log.cc:583
warning messages
Definition: log.h:77
LogComponent(const std::string &name, const enum LogLevel mask=LOG_NONE)
Constructor.
Definition: log.cc:87
print everything
Definition: log.h:92
prefix all trace prints with simulation time
Definition: log.h:96
void LogComponentDisable(char const *name, enum LogLevel level)
Disable the logging output associated with that log component.
Definition: log.cc:354
prefix all trace prints with function
Definition: log.h:95
function tracing
Definition: log.h:86
int32_t m_mask
Blocked LogLevels.
Definition: log.h:327
int32_t m_levels
Enabled LogLevels.
Definition: log.h:326
prefix all trace prints with simulation node
Definition: log.h:97
all prefixes
Definition: log.h:99
void(* LogTimePrinter)(std::ostream &os)
Definition: log.h:248
bool IsNoneEnabled(void) const
Check if all levels are disabled.
Definition: log.cc:252
void(* LogNodePrinter)(std::ostream &os)
Definition: log.h:249
LogLevel
Logging severity classes and levels.
Definition: log.h:71
informational messages (e.g., banners)
Definition: log.h:83
char const * Name(void) const
Get the name of this LogComponent.
Definition: log.cc:276
prefix all trace prints with log level (severity)
Definition: log.h:98
static std::string GetLevelLabel(const enum LogLevel level)
Get the string label for the given LogLevel.
Definition: log.cc:283
LogTimePrinter LogGetTimePrinter(void)
Definition: log.cc:574
void LogComponentPrintList(void)
Print the list of logging messages available.
Definition: log.cc:382
std::string m_name
LogComponent name.
Definition: log.h:328
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:318