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 | |
| 21 | ndn-cxx logging facility provides a mechanism to manage the type of log messages |
| 22 | that are written by classifying log messages by severity levels. Listed below |
| 23 | are the available log levels. |
| 24 | |
| 25 | **Log Levels:** |
| 26 | |
| 27 | :: |
| 28 | |
| 29 | TRACE |
| 30 | DEBUG |
| 31 | INFO |
| 32 | WARN |
| 33 | ERROR |
| 34 | FATAL |
| 35 | |
| 36 | A message's severity level will determine whether the log is written. For instance, |
| 37 | if an application sets its log severity level to DEBUG, all messages marked with |
| 38 | DEBUG, or any of those below that level, are written. FATAL level logs are always |
| 39 | written. |
| 40 | |
| 41 | Setting NDN_LOG requires the following syntax with as many prefixes and |
| 42 | corresponding loglevels as the user desires: |
| 43 | |
| 44 | export NDN_LOG="<prefix1>=<loglevel1>:<prefix2>=<loglevel2>" |
| 45 | |
| 46 | **Examples:** |
| 47 | |
| 48 | :: |
| 49 | |
| 50 | export NDN_LOG="ndn.*=DEBUG" |
| 51 | export NDN_LOG="ndn.UnixTransport=INFO" |
| 52 | export NDN_LOG="sync.Logic=ERROR" |
| 53 | export NDN_LOG="*=DEBUG:ndn.UnixTransport=INFO:sync.Logic=ERROR" |
| 54 | |
| 55 | **Note:** |
| 56 | |
| 57 | Shorter (general) prefixes should be placed before longer (specific) prefixes. |
| 58 | Otherwise, the specific prefix's loglevel will be overwritten. For example, |
| 59 | `export NDN_LOG="ndn.UnixTransport=TRACE:ndn.*=ERROR:*=INFO"` sets all modules |
| 60 | to INFO; it should be written as |
| 61 | `export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE"` for the desired effect. |
| 62 | |
| 63 | **Note:** |
| 64 | |
| 65 | Setting the environment variable with sudo requires the application to be run |
| 66 | in the same command. |
| 67 | |
| 68 | :: |
| 69 | |
| 70 | Correct: |
| 71 | |
| 72 | sudo env NDN_LOG=logLevel ./ndn-application |
| 73 | |
| 74 | sudo -s |
| 75 | export NDN_LOG=logLevel |
| 76 | ./ndn-application |
| 77 | |
| 78 | Incorrect: |
| 79 | |
| 80 | sudo export NDN_LOG=logLevel |
| 81 | sudo ./ndn-application |
| 82 | |
| 83 | NDN_LOG=logLevel sudo ./ndn-application |