Commit d8f5c9f1 authored by Jaroslava Fiedlerova's avatar Jaroslava Fiedlerova

Merge remote-tracking branch 'origin/logging-improvements' into integration_2025_w46 (!3751)

Update log header format to align log output

The new format:
- left-aligns the log header name and enforces a minimum width of 6 characters,
  padding shorter names with spaces while allowing longer names to be printed in
  full
- shortens UTC timestamp
- align function names to 32 characters

Example output:

[19:51:34.647930] [NGAP]   I (ngap_gNB_decode_initiat:100)   Handover Resource Allocation initiating message
[19:51:34.648539] [NGAP]   D (decode_ng_handover_requ:267)   AllowedNSSAI.list.count 2
[19:51:34.648586] [NGAP]   I (ngap_gNB_handle_handove:728)   Received NG Handover Request from AMF OAI-AMF (ID=1)
[19:51:34.648627] [NR_RRC] I (rrc_gNB_process_Handove:1199)  Received Handover Request (on NR Cell ID=11111111, PCI=1)
[19:51:34.648647] [NR_RRC] A (rrc_gNB_create_ue_conte:230)   [--] (cellID 0, UE ID 1 RNTI ffff) Create UE context: CU UE ID 1 DU UE ID 4294967295 (rnti: ffff, random ue id ffffffffffffffff)
[19:51:34.648659] [NR_RRC] A (set_UE_security_algos:692)     [--] (cellID 0, UE ID 1 RNTI ffff) Selected security algorithms: ciphering 0, integrity 2
parents 517a1403 875ec96f
...@@ -461,9 +461,15 @@ int register_log_component(const char *name, const char *fext, int compidx) ...@@ -461,9 +461,15 @@ int register_log_component(const char *name, const char *fext, int compidx)
} }
if (computed_compidx >= 0 && computed_compidx <MAX_LOG_COMPONENTS) { if (computed_compidx >= 0 && computed_compidx <MAX_LOG_COMPONENTS) {
g_log->log_component[computed_compidx].name = strdup(name); log_component_t *c = &g_log->log_component[computed_compidx];
g_log->log_component[computed_compidx].stream = stdout; c->name = strdup(name);
g_log->log_component[computed_compidx].filelog = 0; 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/<name>.%s */ g_log->log_rarely_used[computed_compidx].filelog_name = calloc(1, strlen(name) + 16); /* /tmp/<name>.%s */
sprintf(g_log->log_rarely_used[computed_compidx].filelog_name, "/tmp/%s.", name); 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); strncat(g_log->log_rarely_used[computed_compidx].filelog_name, fext, 3);
...@@ -509,12 +515,15 @@ int logInit (void) ...@@ -509,12 +515,15 @@ int logInit (void)
for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++) for (int i = 0; i < MAX_LOG_PREDEF_COMPONENTS; i++)
register_log_component(comp_name[i], comp_extension[i], 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"; g_log->filelog_name = "/tmp/openair.log";
log_getconfig(g_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 // 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++) { for (int i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
...@@ -575,8 +584,7 @@ static inline int log_header(log_component_t *c, ...@@ -575,8 +584,7 @@ static inline int log_header(log_component_t *c,
struct tm utc_time; struct tm utc_time;
if (gmtime_r(&t.tv_sec, &utc_time) == NULL) if (gmtime_r(&t.tv_sec, &utc_time) == NULL)
abort(); abort();
snprintf(timeString, sizeof(timeString), "%04d-%02d-%02d %02d:%02d:%02d.%06lu UTC ", snprintf(timeString, sizeof(timeString), "[%02d:%02d:%02d.%06lu] ",
utc_time.tm_year + 1900, utc_time.tm_mon + 1, utc_time.tm_mday,
utc_time.tm_hour, utc_time.tm_min, utc_time.tm_sec, t.tv_nsec / 1000); utc_time.tm_hour, utc_time.tm_min, utc_time.tm_sec, t.tv_nsec / 1000);
} else { } else {
snprintf(timeString, sizeof(timeString), "%lu.%06lu ", snprintf(timeString, sizeof(timeString), "%lu.%06lu ",
...@@ -593,15 +601,18 @@ static inline int log_header(log_component_t *c, ...@@ -593,15 +601,18 @@ static inline int log_header(log_component_t *c,
} else { } else {
threadIdString[0] = 0; threadIdString[0] = 0;
} }
return snprintf(log_buffer, buffsize, "%s%s%s[%s] %c %s%s",
flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level], return snprintf(log_buffer,
timeString, buffsize,
threadIdString, "%s%s%s%-8s%s%-*s%s",
c->name, flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level],
flag & FLAG_LEVEL ? g_log->level2string[level] : ' ', timeString,
l, threadIdString,
threadname c->headerName,
); g_log->level2string[level], // will print space if no level selected
l[0] == 0 ? 0 : 32,
l,
threadname);
} }
void logRecord_mt(const char *file, void logRecord_mt(const char *file,
......
...@@ -206,6 +206,7 @@ typedef struct { ...@@ -206,6 +206,7 @@ typedef struct {
typedef struct { typedef struct {
const char *name; const char *name;
char headerName[19];
int level; int level;
int filelog; int filelog;
FILE *stream; FILE *stream;
...@@ -217,7 +218,7 @@ typedef struct { ...@@ -217,7 +218,7 @@ typedef struct {
typedef struct { typedef struct {
log_component_t log_component[MAX_LOG_COMPONENTS]; log_component_t log_component[MAX_LOG_COMPONENTS];
log_component_back_t log_rarely_used[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; int flag;
char *filelog_name; char *filelog_name;
debug_flags_t debug_mask; debug_flags_t debug_mask;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment