From 8ef0956af17f200ffdb74c19c67395747b6b1db2 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Thu, 12 Dec 2013 14:42:43 -0800 Subject: [PATCH] [Bug 1496] Finish the documentation. Also amended scratch-simulator so printing the list of log components works as advertised. --- RELEASE_NOTES | 1 + doc/manual/source/logging.rst | 435 +++++++++++++++++++++++++++------- scratch/scratch-simulator.cc | 3 + src/core/model/log.h | 92 ++++--- 4 files changed, 413 insertions(+), 118 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index e72d20d06..09ee648c2 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -47,6 +47,7 @@ New user-visible features Bugs fixed ---------- +- Bug 1496 - Option to print log level in NS_LOG messages, and documentation. - Bug 1778 - Implement TapBridge::IsLinkUp() function - Bug 1777 - Implement the more direct way of "using" configuration of existing tap interface - Bug 1776 - Improve CRC performance for CsmaNetDevice in emulation modes diff --git a/doc/manual/source/logging.rst b/doc/manual/source/logging.rst index 014e46ecf..7877e2306 100644 --- a/doc/manual/source/logging.rst +++ b/doc/manual/source/logging.rst @@ -22,16 +22,14 @@ the same over time. Users are cautioned against building simulation output frameworks on top of logging code, as the output and the way the output is enabled may change over time. -Logging overview -**************** +Overview +******** |ns3| logging statements are typically used to log various program execution events, such as the occurrence of simulation events or the use of a particular function. -For example, this code snippet is from ``Ipv4L3Protocol::IsDestinationAddress()``: - -:: +For example, this code snippet is from ``Ipv4L3Protocol::IsDestinationAddress()``:: if (address == iaddr.GetBroadcast ()) { @@ -39,71 +37,33 @@ For example, this code snippet is from ``Ipv4L3Protocol::IsDestinationAddress()` return true; } -If logging has been enabled for the ``Ipv4L3Protocol`` component at a level -of ``LOGIC`` or above (see below about logging levels), the statement +If logging has been enabled for the ``Ipv4L3Protocol`` component at a severity +of ``LOGIC`` or above (see below about log severity), the statement will be printed out; otherwise, it will be suppressed. -Logging levels -============== +Enabling Output +=============== -The following levels are defined; each level will enable the levels above -it, with the ``ALL`` level being most verbose: - -#. ``LOG_NONE``: the default, no logging -#. ``LOG_ERROR``: serious error messages only -#. ``LOG_WARN``: warning messages -#. ``LOG_DEBUG``: for use in debugging -#. ``LOG_FUNCTION``: function tracing -#. ``LOG_LOGIC``: control flow tracing within functions -#. ``LOG_ALL``: print everything - -A special logging level will cause logging output to unconditionally -appear on ``std::clog``, regardless of whether the user has explicitly enabled -logging. -This macro, ``NS_LOG_UNCOND()``, can be used like a kind of ``printf()`` in -your code. An example can be found in ``scratch/scratch-simulator.cc``: - -:: - - NS_LOG_UNCOND ("Scratch Simulator"); - -Logging prefixes -================ - -This section still needs documentation; bug 1496 is open on this: - -.. sourcecode:: bash - - $ NS_LOG="*=all|prefix_all" ./waf --run scratch-simulator - Scratch Simulator - ScratchSimulator:main(): [ERROR] error message - ScratchSimulator:main(): [WARN] warn message - ScratchSimulator:main(): [DEBUG] debug message - ScratchSimulator:main(): [INFO] info message - ScratchSimulator:main(function) - ScratchSimulator:main(): [LOGIC] logic message - -Enabling logging output -======================= - -There are two ways that users typically control logging output. The -first is by setting an ``NS_LOG`` environment variable; e.g.: +There are two ways that users typically control log output. The +first is by setting the ``NS_LOG`` environment variable; e.g.: .. sourcecode:: bash $ NS_LOG="*" ./waf --run first -will run the first tutorial program with all logging output. This can -be made more granular by selecting individual components: +will run the ``first`` tutorial program with all logging output. (The +specifics of the ``NS_LOG`` format will be discussed below.) + +This can be made more granular by selecting individual components: .. sourcecode:: bash $ NS_LOG="Ipv4L3Protocol" ./waf --run first - -The second way to enable this is to use explicit statements in your -program, such as in the first tutorial program: -:: +The output can be further tailored with prefix options. + +The second way to enable logging is to use explicit statements in your +program, such as in the ``first`` tutorial program:: int main (int argc, char *argv[]) @@ -112,48 +72,357 @@ program, such as in the first tutorial program: LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); ... -Some helpers have special methods to enable the logging of all components -in a module (across different compilation units, but logically grouped -together such as the |ns3| wifi code: +(The meaning of ``LOG_LEVEL_INFO``, and other possible values, +will be discussed below.) -:: +``NS_LOG`` Syntax +================= + +The ``NS_LOG`` environment variable contains a list of log components +and options. Log components are separated by \`:' characters: + +.. sourcecode:: bash + + $ NS_LOG=":..." + +Options for each log component are given as flags after +each log component: + +.. sourcecode:: bash + + $ NS_LOG="=