blob: f47dd1ac0fffc5c03d16b6037509798d1d9a2d87 [file] [log] [blame]
Davide Pesavento01cea502021-07-31 19:25:42 -04001ndn-cxx logging
2===============
3
4Description
5-----------
dmcoomes57e238f2017-09-11 22:52:32 -05006
7The ndn-cxx logging facility exposes the internal state of NDN libraries and
8applications so the user can investigate internal interactions, such as interest
9dispatch inside ndn::Face, Data and Interest validation in the security framework,
10sync and recovery Interest processing inside ChronoSync, etc. During runtime, the
11user is able to specify the types of messages he or she would like to receive from
12a set of logging modules pre-configured by library and application developers.
13
Davide Pesavento01cea502021-07-31 19:25:42 -040014Environment
15-----------
dmcoomes57e238f2017-09-11 22:52:32 -050016
17One way to control ndn-cxx logging facility is through the environment variable
18``NDN_LOG``. Using this variable, one can set the log levels for the available logging
19modules. Logging modules within different libraries and applications usually have
20distinguishing prefixes (``ndn.``, ``sync.``, etc.), which can be specified when
21setting the environment variable. Wildcards can be used to enable logging for all
22modules (just ``*``) or all modules under a selected prefix (e.g., ``ndn.*``).
23
Alexander Afanasyev75c3af82020-06-10 14:06:46 -040024If an additional environment variable ``NDN_LOG_NOFLUSH`` is set, the automatic flushing
25after each log record will be disabled. This can improve logging performance but may
26cause the log records to appear delayed or, in case of application crash, the last
27few log records may be lost.
28
dmcoomes57e238f2017-09-11 22:52:32 -050029ndn-cxx logging facility provides a mechanism to manage the type of log messages
30that are written by classifying log messages by severity levels. Listed below
31are the available log levels.
32
33**Log Levels:**
34
35::
36
37 TRACE
38 DEBUG
39 INFO
40 WARN
41 ERROR
42 FATAL
43
44A message's severity level will determine whether the log is written. For instance,
45if an application sets its log severity level to DEBUG, all messages marked with
46DEBUG, or any of those below that level, are written. FATAL level logs are always
47written.
48
49Setting NDN_LOG requires the following syntax with as many prefixes and
50corresponding loglevels as the user desires:
51
Davide Pesavento933a5672020-07-03 22:32:43 -040052.. code-block:: sh
53
dmcoomes57e238f2017-09-11 22:52:32 -050054 export NDN_LOG="<prefix1>=<loglevel1>:<prefix2>=<loglevel2>"
55
Davide Pesavento933a5672020-07-03 22:32:43 -040056*Example:*
dmcoomes57e238f2017-09-11 22:52:32 -050057
Davide Pesavento933a5672020-07-03 22:32:43 -040058.. code-block:: sh
dmcoomes57e238f2017-09-11 22:52:32 -050059
60 export NDN_LOG="ndn.*=DEBUG"
61 export NDN_LOG="ndn.UnixTransport=INFO"
62 export NDN_LOG="sync.Logic=ERROR"
63 export NDN_LOG="*=DEBUG:ndn.UnixTransport=INFO:sync.Logic=ERROR"
64
65**Note:**
66
Davide Pesavento933a5672020-07-03 22:32:43 -040067The loglevel assignments in ``NDN_LOG`` are processed left-to-right. Thus, shorter
68(more general) prefixes should be listed before longer (more specific) prefixes.
69Otherwise, the loglevel setting of a more specific prefix may be overwritten by a
70more general assignment appearing later in the string. For example:
71
72.. code-block:: sh
73
74 export NDN_LOG="ndn.UnixTransport=TRACE:ndn.*=ERROR:*=INFO"
75
76will set all modules to INFO. To obtain the desired effect, it should instead be
77written as:
78
79.. code-block:: sh
80
81 export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE"
dmcoomes57e238f2017-09-11 22:52:32 -050082
83**Note:**
84
85Setting the environment variable with sudo requires the application to be run
86in the same command.
87
Davide Pesavento933a5672020-07-03 22:32:43 -040088.. code-block:: sh
dmcoomes57e238f2017-09-11 22:52:32 -050089
Davide Pesavento933a5672020-07-03 22:32:43 -040090 # Correct
91 sudo env NDN_LOG=logLevel ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -050092
Davide Pesavento933a5672020-07-03 22:32:43 -040093 # Also correct
94 sudo -s
95 export NDN_LOG=logLevel
96 ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -050097
Davide Pesavento933a5672020-07-03 22:32:43 -040098 # Incorrect
99 sudo export NDN_LOG=logLevel
100 sudo ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -0500101
Davide Pesavento933a5672020-07-03 22:32:43 -0400102 # Incorrect
103 NDN_LOG=logLevel sudo ./ndn-application