From 7f57019128b5d4500fd6bec80ae4e9d93a478ef3 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 14 Nov 2025 16:01:07 +0100 Subject: [PATCH] log: Only print one space if no level selected Prior to this change, when no "level" option is given to the logging module, we see [PHY] RU 0 RF started cpu_meas_enabled 0 [HW] No connected device, generating void samples... with three spaces, which is too much. This change reduces the amount of spaces to 1 without log level. Co-authored-by: Robert Schmidt --- common/utils/LOG/log.c | 29 +++++++++++++++++------------ common/utils/LOG/log.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index 8e332b7797..bb7d0482cf 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -509,12 +509,15 @@ int logInit (void) for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++) register_log_component(comp_name[i], comp_extension[i], i); - for (int i=0 ; log_level_names[i].name != NULL ; i++) - g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name - g_log->filelog_name = "/tmp/openair.log"; log_getconfig(g_log); + for (int i = 0; log_level_names[i].name != NULL; i++) + if (g_log->flag & FLAG_LEVEL) + snprintf(g_log->level2string[i], sizeof g_log->level2string[i], " %c ", toupper(log_level_names[i].name[0])); + else + snprintf(g_log->level2string[i], sizeof g_log->level2string[i], " "); + // set all unused component items to 0, they are for non predefined components for (int i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); @@ -592,15 +595,17 @@ static inline int log_header(log_component_t *c, } else { threadIdString[0] = 0; } - return snprintf(log_buffer, buffsize, "%s%s%s[%s] %c %s%s", - flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level], - timeString, - threadIdString, - c->name, - flag & FLAG_LEVEL ? g_log->level2string[level] : ' ', - l, - threadname - ); + + return snprintf(log_buffer, + buffsize, + "%s%s%s[%s]%s%s%s", + flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level], + timeString, + threadIdString, + c->name, + g_log->level2string[level], // will print space if no level selected + l, + threadname); } void logRecord_mt(const char *file, diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index c873b0d418..37f903c597 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -217,7 +217,7 @@ typedef struct { typedef struct { log_component_t log_component[MAX_LOG_COMPONENTS]; log_component_back_t log_rarely_used[MAX_LOG_COMPONENTS]; - char level2string[NUM_LOG_LEVEL]; + char level2string[NUM_LOG_LEVEL][4]; int flag; char *filelog_name; debug_flags_t debug_mask;