nRF5 SDK v15.0.0
Flash logger backend

The flash logger backend is used to store logs in non-volatile memory. The backend consists of two logical parts: flashlog and crashlog. Flashlog backend is used to store log entries during application lifetime, while crashlog is used to dump messages logged prior to an error condition (NRF_LOG_FINAL_FLUSH) and between NRF_LOG_FINAL_FLUSH and reset. From the logger perspective, these two parts are seen as independent logger backends. However, internally they share the same scheme of storing and reading log entries.

Flash operations

The module uses dedicated flash pages that are configured in SDK configuration header file. Exact pages can be specified, or pages following the application code can be used (NRF_LOG_BACKEND_FLASH_START_PAGE set to 0). The module uses Flash storage (fstorage) to store the logs. Flashlog uses the Flash storage (fstorage) asynchronous API provided during intialization, while crashlog reinitializes Flash storage (fstorage) to work in a direct, synchronous way. Log entries are serialized and stored in a dedicated area one by one until there is no more space for them. Logs are dropped if there is no space available and the area must be explicitly erased using nrf_log_backend_flash_erase or a CLI command. On initialization, the flash area is scanned to find the last entry and following entries are stored after it.

Flashlog

Once the flashlog backend is initialized and enabled, it receives log messages that match the filtering configured for this backend. Flashlog attempts to write messages to flash using asynchronous Flash storage (fstorage) API. Since access to flash is time-consuming and the area is limited, improper logger filtering configuration might lead to system overload. It is recommended to store only warning and error messages. When flashlog is used, it is recommended to increase NRF_LOG_MSGPOOL_ELEMENT_COUNT. It is related to the fact that flashlog keeps a log message until it is written to flash.

Crashlog

In standard operation, crashlog keeps a FIFO of the most recent log entries which match the filtering. Whenever a new log message is put into the FIFO, the oldest one is freed. Crashlog does not perform any flash operation until panic occurs (NRF_LOG_FINAL_FLUSH). When panic occurs, Flash storage (fstorage) is reconfigured to synchronous mode and all logs from the FIFO are written to flash memory. Any log messages received in panic mode are directly written to flash. When crashlog is used, NRF_LOG_MSGPOOL_ELEMENT_COUNT must be increased at least by NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE, compared to the default value.

Command line interface support

The flash logger backend module provides CLI commands (NRF_LOG_BACKEND_FLASH_CLI_CMDS) for getting the status, reading, and clearing flashlog.


Documentation feedback | Developer Zone | Subscribe | Updated