27 #include "ns3/core-config.h"
43 typedef std::list<std::pair <std::string, LogComponent *> >
ComponentList;
44 typedef std::list<std::pair <std::string, LogComponent *> >::iterator
ComponentListI;
64 char *envVar = getenv (
"NS_LOG");
69 std::string env = envVar;
70 std::string::size_type cur = 0;
71 std::string::size_type next = 0;
72 while (next != std::string::npos)
74 next = env.find_first_of (
":", cur);
75 std::string tmp = std::string (env, cur, next-cur);
76 if (tmp ==
"print-list")
89 : m_levels (0), m_name (name)
95 i != components->end ();
100 NS_FATAL_ERROR (
"Log component \""<<name<<
"\" has already been registered once.");
103 components->push_back (std::make_pair (name,
this));
110 char *envVar = getenv (
"NS_LOG");
115 std::string env = envVar;
116 std::string myName = name;
118 std::string::size_type cur = 0;
119 std::string::size_type next = 0;
120 while (next != std::string::npos)
122 next = env.find_first_of (
":", cur);
123 std::string tmp = std::string (env, cur, next-cur);
124 std::string::size_type equal = tmp.find (
"=");
125 std::string component;
126 if (equal == std::string::npos)
129 if (component == myName || component ==
"*")
138 component = tmp.substr (0, equal);
139 if (component == myName || component ==
"*")
142 std::string::size_type cur_lev;
143 std::string::size_type next_lev = equal;
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 (lev ==
"all")
177 else if (lev ==
"prefix_func")
181 else if (lev ==
"prefix_time")
185 else if (lev ==
"prefix_node")
189 else if (lev ==
"level_error")
193 else if (lev ==
"level_warn")
197 else if (lev ==
"level_debug")
201 else if (lev ==
"level_info")
205 else if (lev ==
"level_function")
209 else if (lev ==
"level_logic")
213 else if (lev ==
"level_all")
217 }
while (next_lev != std::string::npos);
265 for (i = components->begin ();
266 i != components->end ();
269 if (i->first.compare (name) == 0)
271 i->second->Enable (level);
275 if (i == components->end())
280 "\" not found. See above for a list of available log components");
289 i != components->end ();
292 i->second->Enable (level);
301 i != components->end ();
304 if (i->first.compare (name) == 0)
306 i->second->Disable (level);
317 i != components->end ();
320 i->second->Disable (level);
329 i != components->end ();
332 std::cout << i->first <<
"=";
333 if (i->second->IsNoneEnabled ())
335 std::cout <<
"0" << std::endl;
340 std::cout <<
"error";
342 if (i->second->IsEnabled (
LOG_WARN))
344 std::cout <<
"|warn";
348 std::cout <<
"|debug";
350 if (i->second->IsEnabled (
LOG_INFO))
352 std::cout <<
"|info";
356 std::cout <<
"|function";
360 std::cout <<
"|logic";
362 if (i->second->IsEnabled (
LOG_ALL))
366 std::cout << std::endl;
372 char const*name=componentName.c_str();
375 for (i = components->begin ();
376 i != components->end ();
379 if (i->first.compare (name) == 0)
392 char *envVar = getenv (
"NS_LOG");
393 if (envVar == 0 || strlen(envVar) == 0)
397 std::string env = envVar;
399 std::string::size_type cur = 0;
400 std::string::size_type next = 0;
402 while (next != std::string::npos)
404 next = env.find_first_of (
":", cur);
405 std::string tmp = std::string (env, cur, next-cur);
406 std::string::size_type equal = tmp.find (
"=");
407 std::string component;
408 if (equal == std::string::npos)
419 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
420 "\" in env variable NS_LOG, see above for a list of valid components");
425 component = tmp.substr (0, equal);
428 std::string::size_type cur_lev;
429 std::string::size_type next_lev = equal;
432 cur_lev = next_lev + 1;
433 next_lev = tmp.find (
"|", cur_lev);
434 std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
442 || lev ==
"prefix_func"
443 || lev ==
"prefix_time"
444 || lev ==
"prefix_node"
445 || lev ==
"level_error"
446 || lev ==
"level_warn"
447 || lev ==
"level_debug"
448 || lev ==
"level_info"
449 || lev ==
"level_function"
450 || lev ==
"level_logic"
451 || lev ==
"level_all"
460 "\" in env variable NS_LOG for component name " << component);
462 }
while (next_lev != std::string::npos);
467 NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
468 "\" in env variable NS_LOG, see above for a list of valid components");