From 33c8ac5c9019d5cf7f1436ae224244a36725da3e Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Mon, 1 Aug 2022 16:04:06 +0200 Subject: [PATCH] logging: log_msg(): Write directly to Log_output buffer --- src/debug.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 49f1ef002..258f824fc 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -117,15 +117,21 @@ void log_msg(int level, const char *format, ...) va_end(ap); // format the string - char *buffer = (char *) alloca(size + 1); + auto buf = get_log_output().get_buffer(); + const auto& style = get_log_output().get_level_style(level); + + buf.append(style); + buf.append(size, '\0'); + va_start(ap, format); - if (vsprintf(buffer, format, ap) != size) { + if (vsprintf(buf.data() + style.length(), format, ap) != size) { va_end(ap); return; } va_end(ap); - LOG(level) << buffer; + buf.append(TERM_RESET); + buf.submit(); } void log_msg_once(int level, uint32_t id, const char *msg) {