dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 1 | ndn-log |
| 2 | ======= |
| 3 | |
| 4 | The ndn-cxx logging facility exposes the internal state of NDN libraries and |
| 5 | applications so the user can investigate internal interactions, such as interest |
| 6 | dispatch inside ndn::Face, Data and Interest validation in the security framework, |
| 7 | sync and recovery Interest processing inside ChronoSync, etc. During runtime, the |
| 8 | user is able to specify the types of messages he or she would like to receive from |
| 9 | a set of logging modules pre-configured by library and application developers. |
| 10 | |
| 11 | Environment Variable |
| 12 | -------------------- |
| 13 | |
| 14 | One 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 |
| 16 | modules. Logging modules within different libraries and applications usually have |
| 17 | distinguishing prefixes (``ndn.``, ``sync.``, etc.), which can be specified when |
| 18 | setting the environment variable. Wildcards can be used to enable logging for all |
| 19 | modules (just ``*``) or all modules under a selected prefix (e.g., ``ndn.*``). |
| 20 | |
Alexander Afanasyev | 75c3af8 | 2020-06-10 14:06:46 -0400 | [diff] [blame] | 21 | If an additional environment variable ``NDN_LOG_NOFLUSH`` is set, the automatic flushing |
| 22 | after each log record will be disabled. This can improve logging performance but may |
| 23 | cause the log records to appear delayed or, in case of application crash, the last |
| 24 | few log records may be lost. |
| 25 | |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 26 | ndn-cxx logging facility provides a mechanism to manage the type of log messages |
| 27 | that are written by classifying log messages by severity levels. Listed below |
| 28 | are the available log levels. |
| 29 | |
| 30 | **Log Levels:** |
| 31 | |
| 32 | :: |
| 33 | |
| 34 | TRACE |
| 35 | DEBUG |
| 36 | INFO |
| 37 | WARN |
| 38 | ERROR |
| 39 | FATAL |
| 40 | |
| 41 | A message's severity level will determine whether the log is written. For instance, |
| 42 | if an application sets its log severity level to DEBUG, all messages marked with |
| 43 | DEBUG, or any of those below that level, are written. FATAL level logs are always |
| 44 | written. |
| 45 | |
| 46 | Setting NDN_LOG requires the following syntax with as many prefixes and |
| 47 | corresponding loglevels as the user desires: |
| 48 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 49 | .. code-block:: sh |
| 50 | |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 51 | export NDN_LOG="<prefix1>=<loglevel1>:<prefix2>=<loglevel2>" |
| 52 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 53 | *Example:* |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 54 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 55 | .. code-block:: sh |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 56 | |
| 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 Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 64 | The loglevel assignments in ``NDN_LOG`` are processed left-to-right. Thus, shorter |
| 65 | (more general) prefixes should be listed before longer (more specific) prefixes. |
| 66 | Otherwise, the loglevel setting of a more specific prefix may be overwritten by a |
| 67 | more 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 | |
| 73 | will set all modules to INFO. To obtain the desired effect, it should instead be |
| 74 | written as: |
| 75 | |
| 76 | .. code-block:: sh |
| 77 | |
| 78 | export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE" |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 79 | |
| 80 | **Note:** |
| 81 | |
| 82 | Setting the environment variable with sudo requires the application to be run |
| 83 | in the same command. |
| 84 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 85 | .. code-block:: sh |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 86 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 87 | # Correct |
| 88 | sudo env NDN_LOG=logLevel ./ndn-application |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 89 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 90 | # Also correct |
| 91 | sudo -s |
| 92 | export NDN_LOG=logLevel |
| 93 | ./ndn-application |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 94 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 95 | # Incorrect |
| 96 | sudo export NDN_LOG=logLevel |
| 97 | sudo ./ndn-application |
dmcoomes | 57e238f | 2017-09-11 22:52:32 -0500 | [diff] [blame] | 98 | |
Davide Pesavento | 933a567 | 2020-07-03 22:32:43 -0400 | [diff] [blame] | 99 | # Incorrect |
| 100 | NDN_LOG=logLevel sudo ./ndn-application |