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")
88 : m_levels (0), m_name (name)
94 i != components->end ();
99 NS_FATAL_ERROR (
"Log component \""<<name<<
"\" has already been registered once.");
102 components->insert (std::make_pair (name,
this));
109 char *envVar = getenv (
"NS_LOG");
114 std::string env = envVar;
115 std::string myName = name;
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 == myName || component ==
"*" || component ==
"***")
137 component = tmp.substr (0, equal);
138 if (component == myName || 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);
315 for (i = components->begin ();
316 i != components->end ();
319 if (i->first.compare (name) == 0)
321 i->second->Enable (level);
325 if (i == components->end())
330 "\" not found. See above for a list of available log components");
339 i != components->end ();
342 i->second->Enable (level);
351 i != components->end ();
354 if (i->first.compare (name) == 0)
356 i->second->Disable (level);
367 i != components->end ();
370 i->second->Disable (level);
379 i != components->end ();
382 std::cout << i->first <<
"=";
383 if (i->second->IsNoneEnabled ())
385 std::cout <<
"0" << std::endl;
396 std::cout <<
"error";
398 if (i->second->IsEnabled (
LOG_WARN))
400 std::cout <<
"|warn";
404 std::cout <<
"|debug";
406 if (i->second->IsEnabled (
LOG_INFO))
408 std::cout <<
"|info";
412 std::cout <<
"|function";
416 std::cout <<
"|logic";
421 std::cout <<
"|prefix_all";
427 std::cout <<
"|func";
431 std::cout <<
"|time";
435 std::cout <<
"|node";
439 std::cout <<
"|level";
442 std::cout << std::endl;
448 char const*name=componentName.c_str();
451 for (i = components->begin ();
452 i != components->end ();
455 if (i->first.compare (name) == 0)
468 char *envVar = getenv (
"NS_LOG");
469 if (envVar == 0 || std::strlen(envVar) == 0)
473 std::string env = envVar;
475 std::string::size_type cur = 0;
476 std::string::size_type next = 0;
478 while (next != std::string::npos)
480 next = env.find_first_of (
":", cur);
481 std::string tmp = std::string (env, cur, next-cur);
482 std::string::size_type equal = tmp.find (
"=");
483 std::string component;
484 if (equal == std::string::npos)
488 if (
ComponentExists(component) || component ==
"*" || component ==
"***")
495 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
496 "\" in env variable NS_LOG, see above for a list of valid components");
501 component = tmp.substr (0, equal);
504 std::string::size_type cur_lev;
505 std::string::size_type next_lev = equal;
508 cur_lev = next_lev + 1;
509 next_lev = tmp.find (
"|", cur_lev);
510 std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
518 || lev ==
"prefix_func"
520 || lev ==
"prefix_time"
522 || lev ==
"prefix_node"
524 || lev ==
"prefix_level"
526 || lev ==
"prefix_all"
527 || lev ==
"level_error"
528 || lev ==
"level_warn"
529 || lev ==
"level_debug"
530 || lev ==
"level_info"
531 || lev ==
"level_function"
532 || lev ==
"level_logic"
533 || lev ==
"level_all"
543 "\" in env variable NS_LOG for component name " << component);
545 }
while (next_lev != std::string::npos);
550 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
551 "\" in env variable NS_LOG, see above for a list of valid components");
583 : std::basic_ostream<char> (os.rdbuf ()),
void LogComponentEnableAll(enum LogLevel level)
void LogComponentDisableAll(enum LogLevel level)
void LogSetNodePrinter(LogNodePrinter printer)
LogComponent(const std::string &name)
static void CheckEnvironmentVariables(void)
bool IsEnabled(enum LogLevel level) const
#define NS_ASSERT(condition)
ParameterLogger(std::ostream &os)
void Disable(enum LogLevel level)
void LogSetTimePrinter(LogTimePrinter printer)
#define NS_FATAL_ERROR(msg)
fatal error handling
LogTimePrinter g_logTimePrinter
LogNodePrinter LogGetNodePrinter(void)
LogNodePrinter g_logNodePrinter
std::map< std::string, LogComponent * > ComponentList
std::string GetLevelLabel(const enum LogLevel level) const
void LogComponentDisable(char const *name, enum LogLevel level)
void EnvVarCheck(const std::string &name)
std::map< std::string, LogComponent * >::iterator ComponentListI
static class ns3::PrintList g_printList
void(* LogTimePrinter)(std::ostream &os)
bool IsNoneEnabled(void) const
void(* LogNodePrinter)(std::ostream &os)
LogLevel
Logging severity classes and levels.
static bool ComponentExists(std::string componentName)
static ComponentList * GetComponentList(void)
char const * Name(void) const
LogTimePrinter LogGetTimePrinter(void)
void LogComponentPrintList(void)
Print the list of logging messages available.
void Enable(enum LogLevel level)
void LogComponentEnable(char const *name, enum LogLevel level)