blob: fc09e244afd2f83573b5491924856c3648a3da32 [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
Davide Pesavento487cc9a2025-05-01 23:32:05 -040031are the available log levels:
dmcoomes57e238f2017-09-11 22:52:32 -050032
Davide Pesavento487cc9a2025-05-01 23:32:05 -040033* TRACE
34* DEBUG
35* INFO
36* WARN
37* ERROR
38* FATAL
dmcoomes57e238f2017-09-11 22:52:32 -050039
40A message's severity level will determine whether the log is written. For instance,
41if an application sets its log severity level to DEBUG, all messages marked with
42DEBUG, or any of those below that level, are written. FATAL level logs are always
43written.
44
Davide Pesavento487cc9a2025-05-01 23:32:05 -040045Setting ``NDN_LOG`` requires the following syntax with as many prefixes and
dmcoomes57e238f2017-09-11 22:52:32 -050046corresponding loglevels as the user desires:
47
Davide Pesavento487cc9a2025-05-01 23:32:05 -040048.. code-block:: shell
Davide Pesavento933a5672020-07-03 22:32:43 -040049
dmcoomes57e238f2017-09-11 22:52:32 -050050 export NDN_LOG="<prefix1>=<loglevel1>:<prefix2>=<loglevel2>"
51
Davide Pesavento933a5672020-07-03 22:32:43 -040052*Example:*
dmcoomes57e238f2017-09-11 22:52:32 -050053
Davide Pesavento487cc9a2025-05-01 23:32:05 -040054.. code-block:: shell
dmcoomes57e238f2017-09-11 22:52:32 -050055
56 export NDN_LOG="ndn.*=DEBUG"
57 export NDN_LOG="ndn.UnixTransport=INFO"
58 export NDN_LOG="sync.Logic=ERROR"
59 export NDN_LOG="*=DEBUG:ndn.UnixTransport=INFO:sync.Logic=ERROR"
60
61**Note:**
62
Davide Pesavento933a5672020-07-03 22:32:43 -040063The loglevel assignments in ``NDN_LOG`` are processed left-to-right. Thus, shorter
64(more general) prefixes should be listed before longer (more specific) prefixes.
65Otherwise, the loglevel setting of a more specific prefix may be overwritten by a
66more general assignment appearing later in the string. For example:
67
Davide Pesavento487cc9a2025-05-01 23:32:05 -040068.. code-block:: shell
Davide Pesavento933a5672020-07-03 22:32:43 -040069
70 export NDN_LOG="ndn.UnixTransport=TRACE:ndn.*=ERROR:*=INFO"
71
72will set all modules to INFO. To obtain the desired effect, it should instead be
73written as:
74
Davide Pesavento487cc9a2025-05-01 23:32:05 -040075.. code-block:: shell
Davide Pesavento933a5672020-07-03 22:32:43 -040076
77 export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE"
dmcoomes57e238f2017-09-11 22:52:32 -050078
79**Note:**
80
81Setting the environment variable with sudo requires the application to be run
82in the same command.
83
Davide Pesavento487cc9a2025-05-01 23:32:05 -040084.. code-block:: shell
dmcoomes57e238f2017-09-11 22:52:32 -050085
Davide Pesavento933a5672020-07-03 22:32:43 -040086 # Correct
87 sudo env NDN_LOG=logLevel ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -050088
Davide Pesavento933a5672020-07-03 22:32:43 -040089 # Also correct
90 sudo -s
91 export NDN_LOG=logLevel
92 ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -050093
Davide Pesavento933a5672020-07-03 22:32:43 -040094 # Incorrect
95 sudo export NDN_LOG=logLevel
96 sudo ./ndn-application
dmcoomes57e238f2017-09-11 22:52:32 -050097
Davide Pesavento933a5672020-07-03 22:32:43 -040098 # Incorrect
99 NDN_LOG=logLevel sudo ./ndn-application