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 | |
| 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 | |
| 62 | Shorter (general) prefixes should be placed before longer (specific) prefixes. |
| 63 | Otherwise, the specific prefix's loglevel will be overwritten. For example, |
| 64 | `export NDN_LOG="ndn.UnixTransport=TRACE:ndn.*=ERROR:*=INFO"` sets all modules |
| 65 | to INFO; it should be written as |
| 66 | `export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE"` for the desired effect. |
| 67 | |
| 68 | **Note:** |
| 69 | |
| 70 | Setting the environment variable with sudo requires the application to be run |
| 71 | in 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 |