Skip to content

Commit 72f90ee

Browse files
bianikcarlescufi
authored andcommitted
logging: fs backend: optional append to latest file
Make appending to the newest log file in the fs logging backend optional. By default, if there is still free space in the latest log file, the fs logging backend appends to it on startup. This is useful for saving space and avoiding the removal of older log files, if the maximum number of log files has been reached. The drawback of this behavior is, that log files that got appended can not be decoded, if the firmware has changed between startups, for instance by an update, since the log_dictionary.json used for decoding has also changed. Therefore, it may be desirable to deactivate appending to log files. Signed-off-by: Niklas Fabian <[email protected]>
1 parent 04a930f commit 72f90ee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

subsys/logging/backends/Kconfig.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ config LOG_BACKEND_FS_OVERWRITE
3232
When enabled backend overwrites oldest log files.
3333
In other case, when memory is full, new messages are dropped.
3434

35+
config LOG_BACKEND_FS_APPEND_TO_NEWEST_FILE
36+
bool "Append to the newest log file"
37+
default y
38+
help
39+
When enabled and when there is space left in the newest log file,
40+
backend appends to it.
41+
When disabled backend creates a new log file on every startup.
42+
3543
config LOG_BACKEND_FS_FILE_PREFIX
3644
string "Log file name prefix"
3745
default "log."

subsys/logging/backends/log_backend_fs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ static int allocate_new_file(struct fs_file_t *file)
348348
goto out;
349349
}
350350
file_size = fs_tell(file);
351-
if (file_size < CONFIG_LOG_BACKEND_FS_FILE_SIZE) {
351+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FS_APPEND_TO_NEWEST_FILE) &&
352+
file_size < CONFIG_LOG_BACKEND_FS_FILE_SIZE) {
352353
/* There is space left to log to the latest file, no need to create
353354
* a new one or delete old ones at this point.
354355
*/

0 commit comments

Comments
 (0)