26 #include "ns3/core-config.h"
42 typedef std::list<std::pair <std::string, LogComponent *> >
ComponentList;
43 typedef std::list<std::pair <std::string, LogComponent *> >::iterator
ComponentListI;
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->push_back (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 ==
"*")
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);
313 for (i = components->begin ();
314 i != components->end ();
317 if (i->first.compare (name) == 0)
319 i->second->Enable (level);
323 if (i == components->end())
328 "\" not found. See above for a list of available log components");
337 i != components->end ();
340 i->second->Enable (level);
349 i != components->end ();
352 if (i->first.compare (name) == 0)
354 i->second->Disable (level);
365 i != components->end ();
368 i->second->Disable (level);
377 i != components->end ();
380 std::cout << i->first <<
"=";
381 if (i->second->IsNoneEnabled ())
383 std::cout <<
"0" << std::endl;
394 std::cout <<
"error";
396 if (i->second->IsEnabled (
LOG_WARN))
398 std::cout <<
"|warn";
402 std::cout <<
"|debug";
404 if (i->second->IsEnabled (
LOG_INFO))
406 std::cout <<
"|info";
410 std::cout <<
"|function";
414 std::cout <<
"|logic";
419 std::cout <<
"|prefix_all";
425 std::cout <<
"|func";
429 std::cout <<
"|time";
433 std::cout <<
"|node";
437 std::cout <<
"|level";
440 std::cout << std::endl;
446 char const*name=componentName.c_str();
449 for (i = components->begin ();
450 i != components->end ();
453 if (i->first.compare (name) == 0)
466 char *envVar = getenv (
"NS_LOG");
467 if (envVar == 0 || std::strlen(envVar) == 0)
471 std::string env = envVar;
473 std::string::size_type cur = 0;
474 std::string::size_type next = 0;
476 while (next != std::string::npos)
478 next = env.find_first_of (
":", cur);
479 std::string tmp = std::string (env, cur, next-cur);
480 std::string::size_type equal = tmp.find (
"=");
481 std::string component;
482 if (equal == std::string::npos)
493 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
494 "\" in env variable NS_LOG, see above for a list of valid components");
499 component = tmp.substr (0, equal);
502 std::string::size_type cur_lev;
503 std::string::size_type next_lev = equal;
506 cur_lev = next_lev + 1;
507 next_lev = tmp.find (
"|", cur_lev);
508 std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
516 || lev ==
"prefix_func"
518 || lev ==
"prefix_time"
520 || lev ==
"prefix_node"
522 || lev ==
"prefix_level"
524 || lev ==
"prefix_all"
525 || lev ==
"level_error"
526 || lev ==
"level_warn"
527 || lev ==
"level_debug"
528 || lev ==
"level_info"
529 || lev ==
"level_function"
530 || lev ==
"level_logic"
531 || lev ==
"level_all"
541 "\" in env variable NS_LOG for component name " << component);
543 }
while (next_lev != std::string::npos);
548 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
549 "\" in env variable NS_LOG, see above for a list of valid components");