blob: 40db7073a7cc8ea914366b530dea7bb75ecf96d5 [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
49 export NDN_LOG="<prefix1>=<loglevel1>:<prefix2>=<loglevel2>"
50
51**Examples:**
52
53::
54
55 export NDN_LOG="ndn.*=DEBUG"
56 export NDN_LOG="ndn.UnixTransport=INFO"
57 export NDN_LOG="sync.Logic=ERROR"
58 export NDN_LOG="*=DEBUG:ndn.UnixTransport=INFO:sync.Logic=ERROR"
59
60**Note:**
61
62Shorter (general) prefixes should be placed before longer (specific) prefixes.
63Otherwise, the specific prefix's loglevel will be overwritten. For example,
64`export NDN_LOG="ndn.UnixTransport=TRACE:ndn.*=ERROR:*=INFO"` sets all modules
65to INFO; it should be written as
66`export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE"` for the desired effect.
67
68**Note:**
69
70Setting the environment variable with sudo requires the application to be run
71in the same command.
72
73::
74
75 Correct:
76
77 sudo env NDN_LOG=logLevel ./ndn-application
78
79 sudo -s
80 export NDN_LOG=logLevel
81 ./ndn-application
82
83 Incorrect:
84
85 sudo export NDN_LOG=logLevel
86 sudo ./ndn-application
87
88 NDN_LOG=logLevel sudo ./ndn-application