.. include:: replace.txt .. highlight:: cpp .. heading hierarchy: ------------- Chapter ************* Section (#.#) ============= Subsection (#.#.#) ############# Paragraph (no number) Logging ------- The |ns3| logging facility can be used to monitor or debug the progress of simulation programs. Logging output can be enabled by program statements in your ``main()`` program or by the use of the ``NS_LOG`` environment variable. Logging statements are not compiled into optimized builds of |ns3|. To use logging, one must build the (default) debug build of |ns3|. The project makes no guarantee about whether logging output will remain 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. 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()``:: if (address == iaddr.GetBroadcast ()) { NS_LOG_LOGIC ("For me (interface broadcast address)"); return true; } 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. Enabling Output =============== 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. (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 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[]) { LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); ... (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="=