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