logging: Add option to have tag which is prepended to all messages

Tag can be changed at runtime. Feature is enabled by setting
maximum tag length to positive value. Additionally, default
tag can be configured in Kconfig.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-12-22 15:01:15 +01:00 committed by Maureen Helm
commit 194c0acdfd
5 changed files with 75 additions and 1 deletions

View file

@ -495,6 +495,7 @@ static uint32_t prefix_print(const struct log_output *output,
bool stamp = flags & LOG_OUTPUT_FLAG_TIMESTAMP;
bool colors_on = flags & LOG_OUTPUT_FLAG_COLORS;
bool level_on = flags & LOG_OUTPUT_FLAG_LEVEL;
const char *tag = z_log_get_tag();
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET) &&
flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG) {
@ -512,6 +513,10 @@ static uint32_t prefix_print(const struct log_output *output,
level_to_rfc5424_severity(level));
}
if (tag) {
length += print_formatted(output, "%s ", tag);
}
if (stamp) {
length += timestamp_print(output, flags, timestamp);
}