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