27 #include "ns3/core-config.h"    90   char *envVar = getenv (
"NS_LOG");
    95   std::string env = envVar;
    96   std::string::size_type cur = 0;
    97   std::string::size_type next = 0;
    98   while (next != std::string::npos)
   100       next = env.find_first_of (
":", cur);
   101       std::string tmp = std::string (env, cur, next-cur);
   102       if (tmp == 
"print-list")
   115                             const std::string & 
file,
   117   : m_levels (0), m_mask (mask), m_name (name), m_file (
file)
   122   for (LogComponent::ComponentList::const_iterator i = components->begin ();
   123        i != components->end ();
   126       if (i->first == name)
   128           NS_FATAL_ERROR (
"Log component \""<<name<<
"\" has already been registered once.");
   131   components->insert (std::make_pair (name, 
this));
   142       ret = components->at (name);
   144   catch (std::out_of_range&)
   146       NS_FATAL_ERROR (
"Log component \"" << name << 
"\" does not exist.");
   155   char *envVar = getenv (
"NS_LOG");
   160   std::string env = envVar;
   162   std::string::size_type cur = 0;
   163   std::string::size_type next = 0;
   164   while (next != std::string::npos)
   166       next = env.find_first_of (
":", cur);
   167       std::string tmp = std::string (env, cur, next-cur);
   168       std::string::size_type equal = tmp.find (
"=");
   169       std::string component;
   170       if (equal == std::string::npos)
   173           if (component == 
m_name || component == 
"*" || component == 
"***")
   182           component = tmp.substr (0, equal);
   183           if (component == 
m_name || component == 
"*")
   186               std::string::size_type cur_lev;
   187               std::string::size_type next_lev = equal;
   188               bool pre_pipe = 
true;  
   191                   cur_lev = next_lev + 1;
   192                   next_lev = tmp.find (
"|", cur_lev);
   193                   std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
   198                   else if (lev == 
"warn")
   202                   else if (lev == 
"debug")
   206                   else if (lev == 
"info")
   210                   else if (lev == 
"function")
   214                   else if (lev == 
"logic")
   218                   else if ( pre_pipe && ( (lev == 
"all") || (lev == 
"*") ) )
   222                   else if ( (lev == 
"prefix_func") || (lev == 
"func") )
   226                   else if ( (lev == 
"prefix_time") || (lev == 
"time") )
   230                   else if ( (lev == 
"prefix_node") || (lev == 
"node") )
   234                   else if ( (lev == 
"prefix_level") || (lev == 
"level") )
   238                   else if ( (lev == 
"prefix_all") ||
   239                             (!pre_pipe && ( (lev == 
"all") || (lev == 
"*") ) )
   244                   else if (lev == 
"level_error")
   248                   else if (lev == 
"level_warn")
   252                   else if (lev == 
"level_debug")
   256                   else if (lev == 
"level_info")
   260                   else if (lev == 
"level_function")
   264                   else if (lev == 
"level_logic")
   268                   else if (lev == 
"level_all")
   272                   else if (lev == 
"**")
   278                 } 
while (next_lev != std::string::npos);
   372   LogComponent::ComponentList::const_iterator i;
   373   for (i = components->begin (); 
   374        i != components->end (); 
   377       if (i->first.compare (name) == 0) 
   379           i->second->Enable (level);
   383     if (i == components->end())
   388                         "\" not found. See above for a list of available log components");
   396   for (LogComponent::ComponentList::const_iterator i = components->begin ();
   397        i != components->end ();
   400       i->second->Enable (level);
   408   for (LogComponent::ComponentList::const_iterator i = components->begin ();
   409        i != components->end ();
   412       if (i->first.compare (name) == 0) 
   414           i->second->Disable (level);
   424   for (LogComponent::ComponentList::const_iterator i = components->begin ();
   425        i != components->end ();
   428       i->second->Disable (level);
   436   for (LogComponent::ComponentList::const_iterator i = components->begin ();
   437        i != components->end ();
   440       std::cout << i->first << 
"=";
   441       if (i->second->IsNoneEnabled ())
   443           std::cout << 
"0" << std::endl;
   454               std::cout << 
"error";
   456           if (i->second->IsEnabled (
LOG_WARN))
   458               std::cout << 
"|warn";
   462               std::cout << 
"|debug";
   464           if (i->second->IsEnabled (
LOG_INFO))
   466               std::cout << 
"|info";
   470               std::cout << 
"|function";
   474               std::cout << 
"|logic";
   479           std::cout << 
"|prefix_all";
   485               std::cout << 
"|func";
   489               std::cout << 
"|time";
   493               std::cout << 
"|node";
   497               std::cout << 
"|level";
   500       std::cout << std::endl;
   514   char const*name=componentName.c_str();
   516   LogComponent::ComponentList::const_iterator i;
   517   for (i = components->begin ();
   518        i != components->end ();
   521        if (i->first.compare (name) == 0) 
   539   char *envVar = getenv (
"NS_LOG");
   540   if (envVar == 0 || std::strlen(envVar) == 0)
   544   std::string env = envVar;
   546   std::string::size_type cur = 0;
   547   std::string::size_type next = 0;
   549   while (next != std::string::npos)
   551       next = env.find_first_of (
":", cur);
   552       std::string tmp = std::string (env, cur, next-cur);
   553       std::string::size_type equal = tmp.find (
"=");
   554       std::string component;
   555       if (equal == std::string::npos)
   559           if (
ComponentExists(component) || component == 
"*" || component == 
"***")
   566               NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
   567                              "\" in env variable NS_LOG, see above for a list of valid components");
   572           component = tmp.substr (0, equal);
   575               std::string::size_type cur_lev;
   576               std::string::size_type next_lev = equal;
   579                   cur_lev = next_lev + 1;
   580                   next_lev = tmp.find (
"|", cur_lev);
   581                   std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
   589                       || lev == 
"prefix_func"   591                       || lev == 
"prefix_time"   593                       || lev == 
"prefix_node"   595                       || lev == 
"prefix_level"   597                       || lev == 
"prefix_all"   598                       || lev == 
"level_error"   599                       || lev == 
"level_warn"   600                       || lev == 
"level_debug"   601                       || lev == 
"level_info"   602                       || lev == 
"level_function"   603                       || lev == 
"level_logic"   604                       || lev == 
"level_all"   614                                      "\" in env variable NS_LOG for component name " << component);
   616                 } 
while (next_lev != std::string::npos);
   621               NS_FATAL_ERROR(
"Invalid or unregistered component name \"" << component <<
   622                              "\" in env variable NS_LOG, see above for a list of valid components");
   661 ParameterLogger::operator<< <std::string>(
const std::string param)
   665       m_os << 
"\"" << param << 
"\"";
   670       m_os << 
", \"" << param << 
"\"";
   677 ParameterLogger::operator<< <const char *>(
const char * param)
   679   (*this) << std::string (param);
   685 ParameterLogger::operator<< <int8_t>(
const int8_t param)
   689     m_os << static_cast<int16_t> (param);
   694     m_os << 
", " << 
static_cast<int16_t
> (param);
   701 ParameterLogger::operator<< <uint8_t>(
const uint8_t param)
   705     m_os << static_cast<uint16_t> (param);
   710     m_os << 
", " << 
static_cast<uint16_t
> (param);
 NS_FATAL_x macro definitions. 
std::string File(void) const
Get the compilation unit defining this LogComponent. 
LogComponent(const std::string &name, const std::string &file, const enum LogLevel mask=LOG_NONE)
Constructor. 
Serious error messages only. 
Prefix all trace prints with simulation node. 
void LogComponentDisable(char const *name, enum LogLevel level)
Disable the logging output associated with that log component. 
static bool ComponentExists(std::string componentName)
Check if a log component exists. 
bool IsNoneEnabled(void) const
Check if all levels are disabled. 
Informational messages (e.g., banners). 
static void CheckEnvironmentVariables(void)
Parse the NS_LOG environment variable. 
A single log component configuration. 
#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. 
char const  * Name(void) const
Get the name of this LogComponent. 
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. 
Insert , when streaming function arguments. 
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. 
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. 
NS_ASSERT() and NS_ASSERT_MSG() macro definitions. 
Prefix all trace prints with log level (severity). 
void LogComponentPrintList(void)
Print the list of logging messages available. 
Control flow tracing within functions. 
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. 
Prefix all trace prints with simulation time. 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
void LogComponentDisableAll(enum LogLevel level)
Disable all logging for all components. 
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. 
LogComponent & GetLogComponent(const std::string name)
Get the LogComponent registered with the given name. 
LogLevel
Logging severity classes and levels. 
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. 
static LogNodePrinter g_logNodePrinter
The LogNodePrinter. 
Prefix all trace prints with function. 
Rare ad-hoc debug messages. 
bool IsEnabled(const enum LogLevel level) const
Check if this LogComponent is enabled for level. 
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.