|
| 1 | +.. _logging_guide_dictionary: |
| 2 | + |
| 3 | +Dictionary-based Logging |
| 4 | +######################## |
| 5 | + |
| 6 | +Dictionary-based logging, instead of human readable texts, outputs the log |
| 7 | +messages in binary format. This binary format encodes arguments to formatted |
| 8 | +strings in their native storage formats which can be more compact than their |
| 9 | +text equivalents. For statically defined strings (including the format |
| 10 | +strings and any string arguments), references to the ELF file are encoded |
| 11 | +instead of the whole strings. A dictionary created at build time contains |
| 12 | +the mappings between these references and the actual strings. This allows |
| 13 | +the offline parser to obtain the strings from the dictionary to parse |
| 14 | +the log messages. This binary format allows a more compact representation |
| 15 | +of log messages in certain scenarios. However, this requires the use of |
| 16 | +an offline parser and is not as intuitive to use as text-based log messages. |
| 17 | + |
| 18 | +Note that ``long double`` is not supported by Python's ``struct`` module. |
| 19 | +Therefore, log messages with ``long double`` will not display the correct |
| 20 | +values. |
| 21 | + |
| 22 | + |
| 23 | +Configuration |
| 24 | +************* |
| 25 | + |
| 26 | +Here are kconfig options related to dictionary-based logging: |
| 27 | + |
| 28 | +- :option:`CONFIG_LOG_DICTIONARY_SUPPORT` enables dictionary-based logging |
| 29 | + support. This should be selected by the backends which require it. |
| 30 | + |
| 31 | +- The UART backend can be used for dictionary-based logging. These are |
| 32 | + additional config for the UART backend: |
| 33 | + |
| 34 | + - :option:`CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX` tells |
| 35 | + the UART backend to output hexadecimal characters for dictionary based |
| 36 | + logging. This is useful when the log data needs to be captured manually |
| 37 | + via terminals and consoles. |
| 38 | + |
| 39 | + - :option:`CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_BIN` tells |
| 40 | + the UART backend to output binary data. |
| 41 | + |
| 42 | + |
| 43 | +Usage |
| 44 | +***** |
| 45 | + |
| 46 | +When dictionary-based logging is enabled via enabling related logging backends, |
| 47 | +a JSON database file, named :file:`log_dictionary.json`, will be created |
| 48 | +in the build directory. This database file contains information for the parser |
| 49 | +to correctly parse the log data. Note that this database file only works |
| 50 | +with the same build, and cannot be used for any other builds. |
| 51 | + |
| 52 | +To use the log parser: |
| 53 | + |
| 54 | +.. code-block:: console |
| 55 | +
|
| 56 | + ./scripts/logging/dictionary/log_parser.py <build dir>/log_dictionary.json <log data file> |
| 57 | +
|
| 58 | +The parser takes two required arguments, where the first one is the full path |
| 59 | +to the JSON database file, and the second part is the file containing log data. |
| 60 | +Add an optional argument ``--hex`` to the end if the log data file contains |
| 61 | +hexadecimal characters |
| 62 | +(e.g. when ``CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX=y``). This tells |
| 63 | +the parser to convert the hexadecimal characters to binary before parsing. |
| 64 | + |
| 65 | + |
| 66 | +Example |
| 67 | +------- |
| 68 | + |
| 69 | +Please refer to :ref:`logging_dictionary_sample` on how to use the log parser. |
0 commit comments