15#include "ns3/core-config.h" 
   71    std::map<ns3::LogLevel, std::string> labels;
 
   75        if (labels.find(lev) == labels.end())
 
   77            std::string pad{label};
 
   81                pad.insert(pad.size(), 5 - pad.size(), 
' ');
 
   83            std::transform(pad.begin(), pad.end(), pad.begin(), ::toupper);
 
 
 
  149                           const std::string& file,
 
  161    if (components->find(name) != components->end())
 
  163        NS_FATAL_ERROR(
"Log component \"" << name << 
"\" has already been registered once.");
 
  166    components->insert(std::make_pair(name, 
this));
 
 
  177        ret = components->at(name);
 
  179    catch (std::out_of_range&)
 
  181        NS_FATAL_ERROR(
"Log component \"" << name << 
"\" does not exist.");
 
 
  213    NS_ASSERT_MSG(!flags.empty(), 
"Unexpected empty flags from non-empty value");
 
  216    for (
const auto& lev : flags)
 
  222        else if (lev == 
"all" || lev == 
"*")
 
  226        else if (LOG_LABEL_LEVELS.find(lev) != LOG_LABEL_LEVELS.end())
 
  228            level |= LOG_LABEL_LEVELS.at(lev);
 
 
  275    auto it = LOG_LEVEL_LABELS.find(level);
 
  276    if (it != LOG_LEVEL_LABELS.end())
 
 
  287    auto logComponent = components->find(name);
 
  289    if (logComponent == components->end())
 
  291        NS_LOG_UNCOND(
"Logging component \"" << name << 
"\" not found.");
 
  294                       << name << 
"\" not found." 
  295                       << 
" See above for a list of available log components");
 
  298    logComponent->second->Enable(level);
 
 
  305    for (
auto i = components->begin(); i != components->end(); i++)
 
  307        i->second->Enable(level);
 
 
  315    auto logComponent = components->find(name);
 
  317    if (logComponent != components->end())
 
  319        logComponent->second->Disable(level);
 
 
  327    for (
auto i = components->begin(); i != components->end(); i++)
 
  329        i->second->Disable(level);
 
 
  337    std::map<std::string, LogComponent*> componentsSorted;
 
  341        componentsSorted.insert(component);
 
  345    for (
const auto& [name, component] : componentsSorted)
 
  347        std::cout << name << 
"=";
 
  348        if (component->IsNoneEnabled())
 
  350            std::cout << 
"0" << std::endl;
 
  361                std::cout << 
"error";
 
  365                std::cout << 
"|warn";
 
  369                std::cout << 
"|debug";
 
  373                std::cout << 
"|info";
 
  377                std::cout << 
"|function";
 
  381                std::cout << 
"|logic";
 
  386            std::cout << 
"|prefix_all";
 
  392                std::cout << 
"|func";
 
  396                std::cout << 
"|time";
 
  400                std::cout << 
"|node";
 
  404                std::cout << 
"|level";
 
  407        std::cout << std::endl;
 
 
  424    return components->find(componentName) != components->end();
 
 
  437    for (
auto& [component, value] : dict)
 
  439        if (component != 
"*" && component != 
"***" && !
ComponentExists(component))
 
  441            NS_LOG_UNCOND(
"Invalid or unregistered component name \"" << component << 
"\"");
 
  444                "Invalid or unregistered component name \"" 
  446                << 
"\" in env variable NS_LOG, see above for a list of valid components");
 
  457        for (
const auto& flag : flags)
 
  460            if (flag == 
"*" || flag == 
"**")
 
  464            bool ok = LOG_LABEL_LEVELS.find(flag) != LOG_LABEL_LEVELS.end();
 
  468                               << flag << 
"\" in env variable NS_LOG for component name " 
 
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
 
static KeyFoundType Get(const std::string &envvar, const std::string &key="", const std::string &delim=";")
Get the value corresponding to a key from an environment variable.
 
static std::shared_ptr< Dictionary > GetDictionary(const std::string &envvar, const std::string &delim=";")
Get the dictionary for a particular environment variable.
 
A single log component configuration.
 
static ComponentList * GetComponentList()
Get the list of LogComponents.
 
void Enable(const LogLevel level)
Enable this LogComponent at level.
 
std::string File() const
Get the compilation unit defining this LogComponent.
 
int32_t m_levels
Enabled LogLevels.
 
void Disable(const LogLevel level)
Disable logging at level for this LogComponent.
 
static std::string GetLevelLabel(const LogLevel level)
Get the string label for the given LogLevel.
 
void EnvVarCheck()
Parse the NS_LOG environment variable for options relating to this LogComponent.
 
std::string m_file
File defining this LogComponent.
 
bool IsNoneEnabled() const
Check if all levels are disabled.
 
std::string Name() const
Get the name of this LogComponent.
 
std::unordered_map< std::string, LogComponent * > ComponentList
LogComponent name map.
 
int32_t m_mask
Blocked LogLevels.
 
LogComponent(const std::string &name, const std::string &file, const LogLevel mask=LOG_NONE)
Constructor.
 
void SetMask(const LogLevel level)
Prevent the enabling of a specific LogLevel.
 
std::string m_name
LogComponent name.
 
void CommaRest()
Add ,  before every parameter after the first.
 
bool m_first
First argument flag, doesn't get , .
 
ParameterLogger(std::ostream &os)
Constructor.
 
std::ostream & m_os
Underlying output stream.
 
Handler for the undocumented print-list token in NS_LOG which triggers printing of the list of log co...
 
Class Environment declaration.
 
NS_FATAL_x macro definitions.
 
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
 
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
 
static NodePrinter g_logNodePrinter
The Log NodePrinter.
 
static void CheckEnvironmentVariables()
Parse the NS_LOG environment variable.
 
static bool ComponentExists(std::string componentName)
Check if a log component exists.
 
static TimePrinter g_logTimePrinter
The Log TimePrinter.
 
const std::map< std::string, ns3::LogLevel > LOG_LABEL_LEVELS
Mapping of log level text names to values.
 
const std::map< ns3::LogLevel, std::string > LOG_LEVEL_LABELS
Inverse mapping of level values to log level text names.
 
Every class exported by the ns3 library is enclosed in the ns3 namespace.
 
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
 
static PrintList g_printList
Invoke handler for print-list in NS_LOG environment variable.
 
void LogSetTimePrinter(TimePrinter printer)
Set the TimePrinter function to be used to prepend log messages with the simulation time.
 
void(* TimePrinter)(std::ostream &os)
Function signature for features requiring a time formatter, such as logging or ShowProgress.
 
void(* NodePrinter)(std::ostream &os)
Function signature for prepending the node id to a log message.
 
NodePrinter LogGetNodePrinter()
Get the LogNodePrinter function currently in use.
 
StringVector SplitString(const std::string &str, const std::string &delim)
Split a string on a delimiter.
 
void LogComponentDisable(const std::string &name, LogLevel level)
Disable the logging output associated with that log component.
 
LogLevel
Logging severity classes and levels.
 
@ LOG_LEVEL_ALL
Print everything.
 
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
 
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
 
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
 
@ LOG_FUNCTION
Function tracing for non-trivial function calls.
 
@ LOG_ERROR
Serious error messages only.
 
@ LOG_WARN
Warning messages.
 
@ LOG_INFO
Something happened to change state.
 
@ LOG_PREFIX_ALL
All prefixes.
 
@ LOG_LEVEL_FUNCTION
LOG_FUNCTION and above.
 
@ LOG_LEVEL_ERROR
LOG_ERROR and above.
 
@ LOG_ALL
Print everything.
 
@ LOG_LEVEL_WARN
LOG_WARN and above.
 
@ LOG_LEVEL_DEBUG
LOG_DEBUG and above.
 
@ LOG_PREFIX_LEVEL
Prefix all trace prints with log level (severity).
 
@ LOG_LOGIC
Debugging logs for key branches and decisions in a function.
 
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
 
@ LOG_LEVEL_INFO
LOG_INFO and above.
 
@ LOG_DEBUG
Full voluminous logging to support debugging.
 
TimePrinter LogGetTimePrinter()
Get the LogTimePrinter function currently in use.
 
void LogComponentDisableAll(LogLevel level)
Disable all logging for all components.
 
LogComponent & GetLogComponent(const std::string name)
Get the LogComponent registered with the given name.
 
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
 
void LogSetNodePrinter(NodePrinter printer)
Set the LogNodePrinter function to be used to prepend log messages with the node id.
 
void LogComponentPrintList()
Print the list of logging messages available.
 
std::vector< std::string > StringVector
Return type of SplitString.
 
ns3::StringValue attribute value declarations.