Skip to content

Commit e4507ec

Browse files
elliot-wdtlgalak
authored andcommitted
logging: dictionary format output to file
Add the option to send logs to fs backend using new dictionary formatting This can result in much better use of filesystem space Signed-off-by: Elliot Revell-Nash <[email protected]>
1 parent cd536ae commit e4507ec

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

subsys/logging/Kconfig.backends

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,31 @@ config LOG_BACKEND_FS
309309

310310
if LOG_BACKEND_FS
311311

312+
config LOG_BACKEND_FS_OUTPUT_DICTIONARY
313+
bool
314+
depends on LOG2
315+
select LOG_DICTIONARY_SUPPORT
316+
help
317+
FS backend is in dictionary-based logging output mode.
318+
319+
choice
320+
prompt "FS Backend Output Mode"
321+
default LOG_BACKEND_FS_OUTPUT_TEXT
322+
323+
config LOG_BACKEND_FS_OUTPUT_TEXT
324+
bool "Text"
325+
help
326+
Output in text.
327+
328+
config LOG_BACKEND_FS_OUTPUT_DICTIONARY_BIN
329+
bool "Dictionary (binary)"
330+
depends on LOG2
331+
select LOG_BACKEND_FS_OUTPUT_DICTIONARY
332+
help
333+
Dictionary-based logging output in binary.
334+
335+
endchoice
336+
312337
config LOG_BACKEND_FS_OVERWRITE
313338
bool "Enable old log files overwrite"
314339
default y

subsys/logging/log_backend_fs.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <logging/log_backend.h>
10+
#include <logging/log_output_dict.h>
1011
#include <logging/log_backend_std.h>
1112
#include <assert.h>
1213
#include <fs/fs.h>
@@ -432,7 +433,7 @@ static void put(const struct log_backend *const backend,
432433
log_backend_std_put(&log_output, 0, msg);
433434
}
434435

435-
static void log_backend_fs_init(void)
436+
static void log_backend_fs_init(const struct log_backend *const backend)
436437
{
437438
}
438439

@@ -448,10 +449,28 @@ static void dropped(const struct log_backend *const backend, uint32_t cnt)
448449
{
449450
ARG_UNUSED(backend);
450451

451-
log_backend_std_dropped(&log_output, cnt);
452+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FS_OUTPUT_DICTIONARY)) {
453+
log_dict_output_dropped_process(&log_output, cnt);
454+
} else {
455+
log_backend_std_dropped(&log_output, cnt);
456+
}
457+
}
458+
459+
static void process(const struct log_backend *const backend,
460+
union log_msg2_generic *msg)
461+
{
462+
uint32_t flags = log_backend_std_get_flags();
463+
464+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FS_OUTPUT_DICTIONARY)) {
465+
log_dict_output_msg2_process(&log_output,
466+
&msg->log, flags);
467+
} else {
468+
log_output_msg2_process(&log_output, &msg->log, flags);
469+
}
452470
}
453471

454472
static const struct log_backend_api log_backend_fs_api = {
473+
.process = IS_ENABLED(CONFIG_LOG2) ? process : NULL,
455474
.put = put,
456475
.put_sync_string = NULL,
457476
.put_sync_hexdump = NULL,

0 commit comments

Comments
 (0)