.. 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 use the ``default`` or ``debug`` build profiles 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 ``TcpSocketBase::EnterCwr()`` and informs the user that the model is reducing the congestion window and changing state:: NS_LOG_INFO("Enter CWR recovery mode; set cwnd to " << m_tcb->m_cWnd << ", ssthresh to " << m_tcb->m_ssThresh << ", recover to " << m_recover); If logging has been enabled for the ``Ipv4L3Protocol`` component at a severity of ``INFO`` or above (see below about log severity), the statement will be printed out; otherwise, it will be suppressed. The logging implementation is enabled in ``debug`` and ``default`` builds, but disabled in all other build profiles, so that it does not impact the execution speed of more optimized profiles. You can try the example program `log-example.cc` in `src/core/example` with various values for the `NS_LOG` environment variable to see the effect of the options discussed below. 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="*" ./ns3 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" ./ns3 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="=