26 #include "ns3/core-config.h" 
   89   char *envVar = getenv (
"NS_LOG");
 
   94   std::string env = envVar;
 
   95   std::string::size_type cur = 0;
 
   96   std::string::size_type next = 0;
 
   97   while (next != std::string::npos)
 
   99       next = env.find_first_of (
":", cur);
 
  100       std::string tmp = std::string (env, cur, next-cur);
 
  101       if (tmp == 
"print-list")
 
  114                             const std::string & file,
 
  116   : m_levels (0), m_mask (mask), m_name (name), m_file (file)
 
  121   for (LogComponent::ComponentList::const_iterator i = components->begin ();
 
  122        i != components->end ();
 
  125       if (i->first == name)
 
  127           NS_FATAL_ERROR (
"Log component \""<<name<<
"\" has already been registered once.");
 
  130   components->insert (std::make_pair (name, 
this));
 
  137   char *envVar = getenv (
"NS_LOG");
 
  142   std::string env = envVar;
 
  144   std::string::size_type cur = 0;
 
  145   std::string::size_type next = 0;
 
  146   while (next != std::string::npos)
 
  148       next = env.find_first_of (
":", cur);
 
  149       std::string tmp = std::string (env, cur, next-cur);
 
  150       std::string::size_type equal = tmp.find (
"=");
 
  151       std::string component;
 
  152       if (equal == std::string::npos)
 
  155           if (component == 
m_name || component == 
"*" || component == 
"***")
 
  164           component = tmp.substr (0, equal);
 
  165           if (component == 
m_name || component == 
"*")
 
  168               std::string::size_type cur_lev;
 
  169               std::string::size_type next_lev = equal;
 
  170               bool pre_pipe = 
true;  
 
  173                   cur_lev = next_lev + 1;
 
  174                   next_lev = tmp.find (
"|", cur_lev);
 
  175                   std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
 
  180                   else if (lev == 
"warn")
 
  184                   else if (lev == 
"debug")
 
  188                   else if (lev == 
"info")
 
  192                   else if (lev == 
"function")
 
  196                   else if (lev == 
"logic")
 
  200                   else if ( pre_pipe && ( (lev == 
"all") || (lev == 
"*") ) )
 
  204                   else if ( (lev == 
"prefix_func") || (lev == 
"func") )
 
  208                   else if ( (lev == 
"prefix_time") || (lev == 
"time") )
 
  212                   else if ( (lev == 
"prefix_node") || (lev == 
"node") )
 
  216                   else if ( (lev == 
"prefix_level") || (lev == 
"level") )
 
  220                   else if ( (lev == 
"prefix_all") ||
 
  221                             (!pre_pipe && ( (lev == 
"all") || (lev == 
"*") ) )
 
  226                   else if (lev == 
"level_error")
 
  230                   else if (lev == 
"level_warn")
 
  234                   else if (lev == 
"level_debug")
 
  238                   else if (lev == 
"level_info")
 
  242                   else if (lev == 
"level_function")
 
  246                   else if (lev == 
"level_logic")
 
  250                   else if (lev == 
"level_all")
 
  254                   else if (lev == 
"**")
 
  260                 } 
while (next_lev != std::string::npos);
 
  354   LogComponent::ComponentList::const_iterator i;
 
  355   for (i = components->begin (); 
 
  356        i != components->end (); 
 
  359       if (i->first.compare (name) == 0) 
 
  361           i->second->Enable (level);
 
  365     if (i == components->end())
 
  370                         "\" not found. See above for a list of available log components");
 
  378   for (LogComponent::ComponentList::const_iterator i = components->begin ();
 
  379        i != components->end ();
 
  382       i->second->Enable (level);
 
  390   for (LogComponent::ComponentList::const_iterator i = components->begin ();
 
  391        i != components->end ();
 
  394       if (i->first.compare (name) == 0) 
 
  396           i->second->Disable (level);
 
  406   for (LogComponent::ComponentList::const_iterator i = components->begin ();
 
  407        i != components->end ();
 
  410       i->second->Disable (level);
 
  418   for (LogComponent::ComponentList::const_iterator i = components->begin ();
 
  419        i != components->end ();
 
  422       std::cout << i->first << 
"=";
 
  423       if (i->second->IsNoneEnabled ())
 
  425           std::cout << 
"0" << std::endl;
 
  436               std::cout << 
"error";
 
  438           if (i->second->IsEnabled (
LOG_WARN))
 
  440               std::cout << 
"|warn";
 
  444               std::cout << 
"|debug";
 
  446           if (i->second->IsEnabled (
LOG_INFO))
 
  448               std::cout << 
"|info";
 
  452               std::cout << 
"|function";
 
  456               std::cout << 
"|logic";
 
  461           std::cout << 
"|prefix_all";
 
  467               std::cout << 
"|func";
 
  471               std::cout << 
"|time";
 
  475               std::cout << 
"|node";
 
  479               std::cout << 
"|level";
 
  482       std::cout << std::endl;
 
  496   char const*name=componentName.c_str();
 
  498   LogComponent::ComponentList::const_iterator i;
 
  499   for (i = components->begin ();
 
  500        i != components->end ();
 
  503        if (i->first.compare (name) == 0) 
 
  520   char *envVar = getenv (
"NS_LOG");
 
  521   if (envVar == 0 || std::strlen(envVar) == 0)
 
  525   std::string env = envVar;
 
  527   std::string::size_type cur = 0;
 
  528   std::string::size_type next = 0;
 
  530   while (next != std::string::npos)
 
  532       next = env.find_first_of (
":", cur);
 
  533       std::string tmp = std::string (env, cur, next-cur);
 
  534       std::string::size_type equal = tmp.find (
"=");
 
  535       std::string component;
 
  536       if (equal == std::string::npos)
 
  540           if (
ComponentExists(component) || component == 
"*" || component == 
"***")
 
  547               NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
 
  548                              "\" in env variable NS_LOG, see above for a list of valid components");
 
  553           component = tmp.substr (0, equal);
 
  556               std::string::size_type cur_lev;
 
  557               std::string::size_type next_lev = equal;
 
  560                   cur_lev = next_lev + 1;
 
  561                   next_lev = tmp.find (
"|", cur_lev);
 
  562                   std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
 
  570                       || lev == 
"prefix_func" 
  572                       || lev == 
"prefix_time" 
  574                       || lev == 
"prefix_node" 
  576                       || lev == 
"prefix_level" 
  578                       || lev == 
"prefix_all" 
  579                       || lev == 
"level_error" 
  580                       || lev == 
"level_warn" 
  581                       || lev == 
"level_debug" 
  582                       || lev == 
"level_info" 
  583                       || lev == 
"level_function" 
  584                       || lev == 
"level_logic" 
  585                       || lev == 
"level_all" 
  595                                      "\" in env variable NS_LOG for component name " << component);
 
  597                 } 
while (next_lev != std::string::npos);
 
  602               NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
 
  603                              "\" in env variable NS_LOG, see above for a list of valid components");
 
  612   g_logTimePrinter = printer;
 
  626   g_logNodePrinter = printer;
 
NS_FATAL_x macro definitions. 
 
LogComponent(const std::string &name, const std::string &file, const enum LogLevel mask=LOG_NONE)
Constructor. 
 
void LogComponentDisable(char const *name, enum LogLevel level)
Disable the logging output associated with that log component. 
 
static void CheckEnvironmentVariables(void)
Parse the NS_LOG environment variable. 
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
 
static LogTimePrinter g_logTimePrinter
The LogTimePrinter. 
 
ParameterLogger(std::ostream &os)
Constructor. 
 
void Disable(const enum LogLevel level)
Disable logging at level for this LogComponent. 
 
void(* LogTimePrinter)(std::ostream &os)
Function signature for prepending the simulation time to a log message. 
 
void EnvVarCheck(void)
Parse the NS_LOG environment variable for options relating to this LogComponent. 
 
void(* LogNodePrinter)(std::ostream &os)
Function signature for prepending the node id to a log message. 
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate. 
 
std::string m_file
File defining this LogComponent. 
 
Rare ad-hoc debug messages. 
 
Control flow tracing within functions. 
 
Serious error messages only. 
 
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component. 
 
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. 
 
void LogSetNodePrinter(LogNodePrinter printer)
Set the LogNodePrinter function to be used to prepend log messages with the node id. 
 
void SetMask(const enum LogLevel level)
Prevent the enabling of a specific LogLevel. 
 
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG(). 
 
void LogComponentPrintList(void)
Print the list of logging messages available. 
 
LogNodePrinter LogGetNodePrinter(void)
Get the LogNodePrinter function currently in use. 
 
std::map< std::string, LogComponent * > ComponentList
LogComponent name map. 
 
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
Prefix all trace prints with simulation time. 
 
void LogComponentDisableAll(enum LogLevel level)
Disable all logging for all components. 
 
Prefix all trace prints with function. 
 
static ComponentList * GetComponentList(void)
Get the list of LogComponnents. 
 
int32_t m_mask
Blocked LogLevels. 
 
int32_t m_levels
Enabled LogLevels. 
 
static PrintList g_printList
Invoke handler for print-list in NS_LOG environment variable. 
 
void LogSetTimePrinter(LogTimePrinter printer)
Set the LogTimePrinter function to be used to prepend log messages with the simulation time...
 
Handler for print-list token in NS_LOG to print the list of log components. 
 
std::string File(void) const 
Get the compilation unit defining this LogComponent. 
 
static LogNodePrinter g_logNodePrinter
The LogNodePrinter. 
 
Prefix all trace prints with simulation node. 
 
bool IsNoneEnabled(void) const 
Check if all levels are disabled. 
 
LogLevel
Logging severity classes and levels. 
 
static bool ComponentExists(std::string componentName)
Check if a log component exists. 
 
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)
Get the LogTimePrinter function currently in use. 
 
std::string m_name
LogComponent name.