26 #include "ns3/core-config.h"
63 char *envVar = getenv (
"NS_LOG");
68 std::string env = envVar;
69 std::string::size_type cur = 0;
70 std::string::size_type next = 0;
71 while (next != std::string::npos)
73 next = env.find_first_of (
":", cur);
74 std::string tmp = std::string (env, cur, next-cur);
75 if (tmp ==
"print-list")
89 : m_levels (0), m_mask (mask), m_name (name)
95 i != components->end ();
100 NS_FATAL_ERROR (
"Log component \""<<name<<
"\" has already been registered once.");
103 components->insert (std::make_pair (name,
this));
110 char *envVar = getenv (
"NS_LOG");
115 std::string env = envVar;
117 std::string::size_type cur = 0;
118 std::string::size_type next = 0;
119 while (next != std::string::npos)
121 next = env.find_first_of (
":", cur);
122 std::string tmp = std::string (env, cur, next-cur);
123 std::string::size_type equal = tmp.find (
"=");
124 std::string component;
125 if (equal == std::string::npos)
128 if (component ==
m_name || component ==
"*" || component ==
"***")
137 component = tmp.substr (0, equal);
138 if (component ==
m_name || component ==
"*")
141 std::string::size_type cur_lev;
142 std::string::size_type next_lev = equal;
143 bool pre_pipe =
true;
146 cur_lev = next_lev + 1;
147 next_lev = tmp.find (
"|", cur_lev);
148 std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
153 else if (lev ==
"warn")
157 else if (lev ==
"debug")
161 else if (lev ==
"info")
165 else if (lev ==
"function")
169 else if (lev ==
"logic")
173 else if ( pre_pipe && ( (lev ==
"all") || (lev ==
"*") ) )
177 else if ( (lev ==
"prefix_func") || (lev ==
"func") )
181 else if ( (lev ==
"prefix_time") || (lev ==
"time") )
185 else if ( (lev ==
"prefix_node") || (lev ==
"node") )
189 else if ( (lev ==
"prefix_level") || (lev ==
"level") )
193 else if ( (lev ==
"prefix_all") ||
194 (!pre_pipe && ( (lev ==
"all") || (lev ==
"*") ) )
199 else if (lev ==
"level_error")
203 else if (lev ==
"level_warn")
207 else if (lev ==
"level_debug")
211 else if (lev ==
"level_info")
215 else if (lev ==
"level_function")
219 else if (lev ==
"level_logic")
223 else if (lev ==
"level_all")
227 else if (lev ==
"**")
233 }
while (next_lev != std::string::npos);
322 for (i = components->begin ();
323 i != components->end ();
326 if (i->first.compare (name) == 0)
328 i->second->Enable (level);
332 if (i == components->end())
337 "\" not found. See above for a list of available log components");
346 i != components->end ();
349 i->second->Enable (level);
358 i != components->end ();
361 if (i->first.compare (name) == 0)
363 i->second->Disable (level);
374 i != components->end ();
377 i->second->Disable (level);
386 i != components->end ();
389 std::cout << i->first <<
"=";
390 if (i->second->IsNoneEnabled ())
392 std::cout <<
"0" << std::endl;
403 std::cout <<
"error";
405 if (i->second->IsEnabled (
LOG_WARN))
407 std::cout <<
"|warn";
411 std::cout <<
"|debug";
413 if (i->second->IsEnabled (
LOG_INFO))
415 std::cout <<
"|info";
419 std::cout <<
"|function";
423 std::cout <<
"|logic";
428 std::cout <<
"|prefix_all";
434 std::cout <<
"|func";
438 std::cout <<
"|time";
442 std::cout <<
"|node";
446 std::cout <<
"|level";
449 std::cout << std::endl;
455 char const*name=componentName.c_str();
458 for (i = components->begin ();
459 i != components->end ();
462 if (i->first.compare (name) == 0)
475 char *envVar = getenv (
"NS_LOG");
476 if (envVar == 0 || std::strlen(envVar) == 0)
480 std::string env = envVar;
482 std::string::size_type cur = 0;
483 std::string::size_type next = 0;
485 while (next != std::string::npos)
487 next = env.find_first_of (
":", cur);
488 std::string tmp = std::string (env, cur, next-cur);
489 std::string::size_type equal = tmp.find (
"=");
490 std::string component;
491 if (equal == std::string::npos)
495 if (
ComponentExists(component) || component ==
"*" || component ==
"***")
502 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
503 "\" in env variable NS_LOG, see above for a list of valid components");
508 component = tmp.substr (0, equal);
511 std::string::size_type cur_lev;
512 std::string::size_type next_lev = equal;
515 cur_lev = next_lev + 1;
516 next_lev = tmp.find (
"|", cur_lev);
517 std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
525 || lev ==
"prefix_func"
527 || lev ==
"prefix_time"
529 || lev ==
"prefix_node"
531 || lev ==
"prefix_level"
533 || lev ==
"prefix_all"
534 || lev ==
"level_error"
535 || lev ==
"level_warn"
536 || lev ==
"level_debug"
537 || lev ==
"level_info"
538 || lev ==
"level_function"
539 || lev ==
"level_logic"
540 || lev ==
"level_all"
550 "\" in env variable NS_LOG for component name " << component);
552 }
while (next_lev != std::string::npos);
557 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
558 "\" in env variable NS_LOG, see above for a list of valid components");
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
void LogComponentDisableAll(enum LogLevel level)
Disable all logging for all components.
void LogSetNodePrinter(LogNodePrinter printer)
static void CheckEnvironmentVariables(void)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
ParameterLogger(std::ostream &os)
Constructor.
void Disable(const enum LogLevel level)
Disable logging at level for this LogComponent.
void EnvVarCheck(void)
Parse the NS_LOG environment variable for options relating to this LogComponent.
#define NS_FATAL_ERROR(msg)
fatal error handling
void LogSetTimePrinter(LogTimePrinter printer)
rare ad-hoc debug messages
control flow tracing within functions
serious error messages only
void Enable(const enum LogLevel level)
Enable this LogComponent at level
bool IsEnabled(const enum LogLevel level) const
Check if this LogComponent is enabled for level
static LogTimePrinter g_logTimePrinter
void SetMask(const enum LogLevel level)
Prevent the enabling of a specific LogLevel.
LogNodePrinter LogGetNodePrinter(void)
LogComponent(const std::string &name, const enum LogLevel mask=LOG_NONE)
Constructor.
static LogNodePrinter g_logNodePrinter
std::map< std::string, LogComponent * > ComponentList
prefix all trace prints with simulation time
void LogComponentDisable(char const *name, enum LogLevel level)
Disable the logging output associated with that log component.
prefix all trace prints with function
int32_t m_mask
Blocked LogLevels.
int32_t m_levels
Enabled LogLevels.
std::map< std::string, LogComponent * >::iterator ComponentListI
prefix all trace prints with simulation node
static class ns3::PrintList g_printList
void(* LogTimePrinter)(std::ostream &os)
bool IsNoneEnabled(void) const
Check if all levels are disabled.
void(* LogNodePrinter)(std::ostream &os)
LogLevel
Logging severity classes and levels.
static bool ComponentExists(std::string componentName)
static ComponentList * GetComponentList(void)
informational messages (e.g., banners)
char const * Name(void) const
Get the name of this LogComponent.
prefix all trace prints with log level (severity)
static std::string GetLevelLabel(const enum LogLevel level)
Get the string label for the given LogLevel.
LogTimePrinter LogGetTimePrinter(void)
void LogComponentPrintList(void)
Print the list of logging messages available.
std::string m_name
LogComponent name.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.