From 090cf00c76b3d9cdf16ca2987044593f425c95ba Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 12 Nov 2025 16:14:11 +0100 Subject: [PATCH 1/4] Simplify logging UTC option to only show time We probably almost never care about the date, but it takes a lot of space. Remove it; if somebody needs the full time stamp including the date, we could still add it with a new option. --- common/utils/LOG/log.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index 91c97ac1ac..8e332b7797 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -575,8 +575,7 @@ static inline int log_header(log_component_t *c, struct tm utc_time; if (gmtime_r(&t.tv_sec, &utc_time) == NULL) abort(); - snprintf(timeString, sizeof(timeString), "%04d-%02d-%02d %02d:%02d:%02d.%06lu UTC ", - utc_time.tm_year + 1900, utc_time.tm_mon + 1, utc_time.tm_mday, + snprintf(timeString, sizeof(timeString), "[%02d:%02d:%02d.%06lu] ", utc_time.tm_hour, utc_time.tm_min, utc_time.tm_sec, t.tv_nsec / 1000); } else { snprintf(timeString, sizeof(timeString), "%lu.%06lu ", From 7f57019128b5d4500fd6bec80ae4e9d93a478ef3 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 14 Nov 2025 16:01:07 +0100 Subject: [PATCH 2/4] 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; From ea1aa382c3932606b388a599bfc7e374d1581e6d Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 14 Nov 2025 17:05:49 +0100 Subject: [PATCH 3/4] Update log header format to improve visual alignment The new format left-aligns the component name and enforces a minimum width of 7 (log component) characters, padding shorter names with spaces after the closing "]". Example output: [14:05:43.395376] [E1AP] I releasing UE 1 [14:05:43.395400] [GTPU] I [91] UE ID 1: Delete all tunnels (1 tunnels) [14:05:43.395414] [NR_RRC] A [DL] (cellID bc614e, UE ID 1 RNTI 8e27) Send RRC Release [14:05:43.395431] [RRC] I UE 1: received bearer release complete [14:05:43.424551] [RLC] W Remove UE 36391 [14:05:43.424597] [NR_RRC] I removed UE CU UE ID 1/RNTI 8e27 [14:05:43.424773] [NR_RRC] A [--] (cellID bc614e, UE ID 1 RNTI 8e27) Remove UE context [14:05:43.425205] [NR_MAC] I Remove NR rnti 0x8e27 [14:05:43.582158] [HW] W Lost socket ^C ** Caught SIGTERM, shutting down Returned from ITTI signal handler [14:05:43.948721] [GNB_APP] I stopping nr-softmodem [14:05:43.948746] [PHY] I Killing gNB 0 processing threads [14:05:44.574818] [PHY] I Stopping RU 0 processing threads [14:05:44.575000] [PHY] I RU 0 RF device stopped [14:05:44.575006] [GNB_APP] I turned off RU rfdevice --- common/utils/LOG/log.c | 16 +++++++++++----- common/utils/LOG/log.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index bb7d0482cf..354fae2fb1 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -461,9 +461,15 @@ int register_log_component(const char *name, const char *fext, int compidx) } if (computed_compidx >= 0 && computed_compidx log_component[computed_compidx].name = strdup(name); - g_log->log_component[computed_compidx].stream = stdout; - g_log->log_component[computed_compidx].filelog = 0; + log_component_t *c = &g_log->log_component[computed_compidx]; + c->name = strdup(name); + int n = snprintf(c->headerName, sizeof(c->headerName), "[%s", c->name); + if (n >= sizeof(c->headerName) - 1) // snprintf() truncated + n = sizeof(c->headerName) - 2; + c->headerName[n] = ']'; + c->headerName[n + 1] = 0; + c->stream = stdout; + c->filelog = 0; g_log->log_rarely_used[computed_compidx].filelog_name = calloc(1, strlen(name) + 16); /* /tmp/.%s */ sprintf(g_log->log_rarely_used[computed_compidx].filelog_name, "/tmp/%s.", name); strncat(g_log->log_rarely_used[computed_compidx].filelog_name, fext, 3); @@ -598,11 +604,11 @@ static inline int log_header(log_component_t *c, return snprintf(log_buffer, buffsize, - "%s%s%s[%s]%s%s%s", + "%s%s%s%-8s%s%s%s", flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level], timeString, threadIdString, - c->name, + c->headerName, g_log->level2string[level], // will print space if no level selected l, threadname); diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 37f903c597..312f2c9510 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -206,6 +206,7 @@ typedef struct { typedef struct { const char *name; + char headerName[19]; int level; int filelog; FILE *stream; From 875ec96fce0b3ac0f15dde5abdab8ad34c4a90cf Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 14 Nov 2025 17:07:13 +0100 Subject: [PATCH 4/4] When logging function names, align to 32 characters --- common/utils/LOG/log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index 354fae2fb1..23aa075ca1 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -604,12 +604,13 @@ static inline int log_header(log_component_t *c, return snprintf(log_buffer, buffsize, - "%s%s%s%-8s%s%s%s", + "%s%s%s%-8s%s%-*s%s", flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level], timeString, threadIdString, c->headerName, g_log->level2string[level], // will print space if no level selected + l[0] == 0 ? 0 : 32, l, threadname); }