src/core/log.h
changeset 2983 e3a416fe9dd5
parent 2982 a7e3e54c7e94
child 2986 484e5030c441
equal deleted inserted replaced
2982:a7e3e54c7e94 2983:e3a416fe9dd5
    38  * messages, use the ns3::LogComponentEnable
    38  * messages, use the ns3::LogComponentEnable
    39  * function or use the NS_LOG environment variable 
    39  * function or use the NS_LOG environment variable 
    40  *
    40  *
    41  * Use the environment variable NS_LOG to define a ':'-separated list of
    41  * Use the environment variable NS_LOG to define a ':'-separated list of
    42  * logging components to enable. For example (using bash syntax), 
    42  * logging components to enable. For example (using bash syntax), 
    43  * NS_LOG="OlsrAgent" would enable one component; 
    43  * NS_LOG="OlsrAgent" would enable one component at all log levels. 
    44  * NS_LOG="OlsrAgent:Ipv4L3Protocol" would enable two
    44  * NS_LOG="OlsrAgent:Ipv4L3Protocol" would enable two components, 
    45  * components, etc.  NS_LOG="*" will enable all available log components at
    45  * at all log levels, etc.  
    46  * all levels.
    46  * NS_LOG="*" will enable all available log components at all levels.
    47  *
    47  *
    48  * To obtain more components than just debug log level, more components 
    48  * To control more selectively the log levels for each component, use
    49  * can be enabled selectively with the following
    49  * this syntax: NS_LOG='Component1=func|warn:Component2=error|debug'
    50  * syntax: NS_LOG='Component1=func|param|warn:Component2=error|debug'
    50  * This example would enable the 'func', and 'warn' log
    51  * This example would enable the 'func', 'param', and 'warn' log
       
    52  * levels for 'Component1' and the 'error' and 'debug' log levels
    51  * levels for 'Component1' and the 'error' and 'debug' log levels
    53  * for 'Component2'.  The wildcard can be used here as well.  For example
    52  * for 'Component2'.  The wildcard can be used here as well.  For example
    54  * NS_LOG='*=level_all|prefix' would enable all log levels and prefix all
    53  * NS_LOG='*=level_all|prefix' would enable all log levels and prefix all
    55  * prints with the component and function names.
    54  * prints with the component and function names.
    56  *
       
    57  */
    55  */
    58 
    56 
    59 /**
    57 /**
    60  * \ingroup logging
    58  * \ingroup logging
    61  * \param name a string
    59  * \param name a string
   155 /**
   153 /**
   156  * \ingroup logging
   154  * \ingroup logging
   157  *
   155  *
   158  * Output the name of the function.
   156  * Output the name of the function.
   159  */
   157  */
   160 #define NS_LOG_FUNCTION                                         \
   158 #define NS_LOG_FUNCTION_NOARGS()                                \
   161   do                                                            \
   159   do                                                            \
   162     {                                                           \
   160     {                                                           \
   163       if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
   161       if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
   164         {                                                       \
   162         {                                                       \
   165           APPEND_TIME_PREFIX;                                   \
   163           APPEND_TIME_PREFIX;                                   \
   172 
   170 
   173 /**
   171 /**
   174  * \ingroup logging
   172  * \ingroup logging
   175  * \param parameters the parameters to output.
   173  * \param parameters the parameters to output.
   176  *
   174  *
   177  * If log level LOG_PARAM is enabled, this macro will output
   175  * If log level LOG_FUNCTION is enabled, this macro will output
   178  * all input parameters separated by ", ".
   176  * all input parameters separated by ", ".
   179  *
   177  *
   180  * Typical usage looks like:
   178  * Typical usage looks like:
   181  * \code
   179  * \code
   182  * NS_LOG_PARAMS (aNumber<<anotherNumber);
   180  * NS_LOG_FUNCTION (aNumber<<anotherNumber);
   183  * \endcode
   181  * \endcode
   184  * And the output will look like:
   182  * And the output will look like:
   185  * \code
   183  * \code
   186  * Component:Function (aNumber, anotherNumber)
   184  * Component:Function (aNumber, anotherNumber)
   187  * \endcode
   185  * \endcode
   188  */
   186  */
   189 #define NS_LOG_PARAMS(parameters)                       \
   187 #define NS_LOG_FUNCTION(parameters)                     \
   190   do                                                    \
   188   do                                                    \
   191     {                                                   \
   189     {                                                   \
   192       if (g_log.IsEnabled (ns3::LOG_PARAM))             \
   190       if (g_log.IsEnabled (ns3::LOG_FUNCTION))          \
   193         {                                               \
   191         {                                               \
   194           APPEND_TIME_PREFIX;                           \
   192           APPEND_TIME_PREFIX;                           \
   195           std::clog << g_log.Name () << ":"             \
   193           std::clog << g_log.Name () << ":"             \
   196                     << __FUNCTION__ << "(";             \
   194                     << __FUNCTION__ << "(";             \
   197           ParameterLogger (std::clog)  << parameters;   \
   195           ParameterLogger (std::clog)  << parameters;   \
   241   LOG_LEVEL_INFO     = 0x0000000f,
   239   LOG_LEVEL_INFO     = 0x0000000f,
   242 
   240 
   243   LOG_FUNCTION       = 0x00000010, // function tracing
   241   LOG_FUNCTION       = 0x00000010, // function tracing
   244   LOG_LEVEL_FUNCTION = 0x0000001f, 
   242   LOG_LEVEL_FUNCTION = 0x0000001f, 
   245 
   243 
   246   LOG_PARAM          = 0x00000020, // parameters to functions
   244   LOG_LOGIC          = 0x00000020, // control flow tracing within functions
   247   LOG_LEVEL_PARAM    = 0x0000003f,
   245   LOG_LEVEL_LOGIC    = 0x0000003f,
   248 
       
   249   LOG_LOGIC          = 0x00000040, // control flow tracing within functions
       
   250   LOG_LEVEL_LOGIC    = 0x0000007f,
       
   251 
   246 
   252   LOG_ALL            = 0x3fffffff, // print everything
   247   LOG_ALL            = 0x3fffffff, // print everything
   253   LOG_LEVEL_ALL      = LOG_ALL,
   248   LOG_LEVEL_ALL      = LOG_ALL,
   254 
   249 
   255   LOG_PREFIX_FUNC    = 0x80000000, // prefix all trace prints with function
   250   LOG_PREFIX_FUNC    = 0x80000000, // prefix all trace prints with function
   365 #define NS_LOG(level, msg)
   360 #define NS_LOG(level, msg)
   366 #define NS_LOG_ERROR(msg)
   361 #define NS_LOG_ERROR(msg)
   367 #define NS_LOG_WARN(msg)
   362 #define NS_LOG_WARN(msg)
   368 #define NS_LOG_DEBUG(msg)
   363 #define NS_LOG_DEBUG(msg)
   369 #define NS_LOG_INFO(msg)
   364 #define NS_LOG_INFO(msg)
   370 #define NS_LOG_FUNCTION
   365 #define NS_LOG_FUNCTION_NOARGS()
   371 #define NS_LOG_PARAMS(parameters)
   366 #define NS_LOG_FUNCTION()
   372 #define NS_LOG_LOGIC(msg)
   367 #define NS_LOG_LOGIC(msg)
   373 #define NS_LOG_UNCOND(msg)
   368 #define NS_LOG_UNCOND(msg)
   374 
   369 
   375 #define LogComponentPrintList
   370 #define LogComponentPrintList
   376 #define LogComponentEnable(name,level)
   371 #define LogComponentEnable(name,level)