Skip to content

Commit f7412dc

Browse files
Shawn-Huang724henrikbrixandersen
authored andcommitted
logging: allow simplified logging of backend
This allows no timestamps and level prefixes in backend log output. Signed-off-by: Shawn Huang <[email protected]>
1 parent 345121a commit f7412dc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

doc/services/logging/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ with function name. Hexdump messages are not prepended.
181181
:kconfig:option:`CONFIG_LOG_FUNC_NAME_PREFIX_DBG`: Prepend standard DEBUG log messages
182182
with function name. Hexdump messages are not prepended.
183183

184+
:kconfig:option:`CONFIG_LOG_BACKEND_SHOW_TIMESTAMP`: Enables backend to print timestamps
185+
with log.
186+
187+
:kconfig:option:`CONFIG_LOG_BACKEND_SHOW_LEVEL`: Enables backend to print levels with log.
188+
184189
:kconfig:option:`CONFIG_LOG_BACKEND_SHOW_COLOR`: Enables coloring of errors (red)
185190
and warnings (yellow).
186191

include/zephyr/logging/log_backend_std.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ extern "C" {
2323

2424
static inline uint32_t log_backend_std_get_flags(void)
2525
{
26-
uint32_t flags = (LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP);
26+
uint32_t flags = 0;
27+
28+
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_TIMESTAMP)) {
29+
flags |= LOG_OUTPUT_FLAG_TIMESTAMP;
30+
}
31+
32+
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_LEVEL)) {
33+
flags |= LOG_OUTPUT_FLAG_LEVEL;
34+
}
2735

2836
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
2937
flags |= LOG_OUTPUT_FLAG_COLORS;

subsys/logging/Kconfig.formatting

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ config LOG_IMMEDIATE_CLEAN_OUTPUT
132132
this option is causing interrupts locking for significant amount of
133133
time (up to multiple milliseconds).
134134

135+
config LOG_BACKEND_SHOW_TIMESTAMP
136+
bool "Timestamps in the backend"
137+
default y
138+
help
139+
When enabled, selected backend prints timestamps with log.
140+
141+
config LOG_BACKEND_SHOW_LEVEL
142+
bool "Levels in the backend"
143+
default y
144+
help
145+
When enabled, selected backend prints levels with log.
146+
135147
config LOG_BACKEND_SHOW_COLOR
136148
bool "Colors in the backend"
137149
default y if LOG_BACKEND_UART || LOG_BACKEND_NATIVE_POSIX || LOG_BACKEND_RTT \
@@ -172,7 +184,7 @@ config LOG_BACKEND_SUPPORTS_FORMAT_TIMESTAMP
172184
config LOG_BACKEND_FORMAT_TIMESTAMP
173185
bool "Timestamp formatting in the backend"
174186
depends on LOG_BACKEND_SUPPORTS_FORMAT_TIMESTAMP
175-
default y
187+
default y if LOG_BACKEND_SHOW_TIMESTAMP
176188
help
177189
When enabled timestamp is formatted.
178190

0 commit comments

Comments
 (0)