From 321b1c4ce1ce6c606f259dfac4221013ac46e1be Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 18 Feb 2025 18:21:03 +0100 Subject: [PATCH] Increase maximum logging line length for in-memory log - Increase the maximum logging line for print done through log_output_memory(). The reason is that we hit this line length when printing some machine generated configuration (XML) through the M-plane. Increase to make more of it visible. - To limit the impact, only increase this locally in function log_output_memory(), and statically assert that it will never be larger than 64 kB. In other places, we use the old limit. - Move the definition MAX_LOG_TOTAL to log.c, because it's only used there. --- common/utils/LOG/log.c | 30 +++++++++++++++++++----------- common/utils/LOG/log.h | 6 ------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index 148da232ae..61003857ab 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -52,6 +52,13 @@ // main log variables +/** @defgroup _max_length Maximum Length of LOG + * @ingroup _macro + * @brief the macros that describe the maximum length of LOG + * @{*/ + +#define MAX_LOG_TOTAL 16384 /*!< \brief the maximum length of a log */ + // Fixme: a better place to be shure it is called void read_cpu_hardware (void) __attribute__ ((constructor)); #if !defined(__arm__) && !defined(__aarch64__) @@ -877,31 +884,32 @@ static void log_output_memory(log_component_t *c, const char *file, const char * * correctly. It was not a big problem because in practice MAX_LOG_TOTAL is * big enough so that the buffer is never full. */ - char log_buffer[MAX_LOG_TOTAL]; + static_assert(4 * MAX_LOG_TOTAL <= 65536, "log buffer limited to 64kB, please reduce MAX_LOG_TOTAL\n"); + char log_buffer[4 * MAX_LOG_TOTAL]; // make sure that for log trace the extra info is only printed once, reset when the level changes if (level < OAILOG_TRACE) { - int n = log_header(c, log_buffer+len, MAX_LOG_TOTAL, file, func, line, level); + int n = log_header(c, log_buffer+len, sizeof(log_buffer), file, func, line, level); if (n > 0) { len += n; - if (len > MAX_LOG_TOTAL) { - len = MAX_LOG_TOTAL; + if (len > sizeof(log_buffer)) { + len = sizeof(log_buffer); } } } - int n = vsnprintf(log_buffer+len, MAX_LOG_TOTAL-len, format, args); + int n = vsnprintf(log_buffer+len, sizeof(log_buffer)-len, format, args); if (n > 0) { len += n; - if (len > MAX_LOG_TOTAL) { - len = MAX_LOG_TOTAL; + if (len > sizeof(log_buffer)) { + len = sizeof(log_buffer); } } if (!((g_log->flag) & FLAG_NOCOLOR)) { - int n = snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]); + int n = snprintf(log_buffer+len, sizeof(log_buffer)-len, "%s", log_level_highlight_end[level]); if (n > 0) { len += n; - if (len > MAX_LOG_TOTAL) { - len = MAX_LOG_TOTAL; + if (len > sizeof(log_buffer)) { + len = sizeof(log_buffer); } } } @@ -941,7 +949,7 @@ static void log_output_memory(log_component_t *c, const char *file, const char * } } }else{ - AssertFatal(len >= 0 && len <= MAX_LOG_TOTAL, "Bad len %d\n", len); + AssertFatal(len >= 0 && len <= sizeof(log_buffer), "Bad len %d\n", len); if (write(fileno(c->stream), log_buffer, len)) {}; } } diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index d153a4aeaf..7b9b570a06 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -65,12 +65,6 @@ extern "C" { #endif -/** @defgroup _max_length Maximum Length of LOG - * @ingroup _macro - * @brief the macros that describe the maximum length of LOG - * @{*/ - -#define MAX_LOG_TOTAL 16384 /*!< \brief the maximum length of a log */ /** @}*/ /** @defgroup _log_level Message levels defined by LOG