From ea1aa382c3932606b388a599bfc7e374d1581e6d Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 14 Nov 2025 17:05:49 +0100 Subject: [PATCH] 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;