commit 0f8298dd73f11ea5ccc8897dafcbedde1f211fad
parent e014f5f59f83e15ed5c83ff3e3bf29f249e11aba
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Mon, 4 Nov 2024 23:11:59 +0100
util: Modify logging behaviour to append newline if absent to prevent clobbering output. Fixes #9313
Diffstat:
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/lib/util/common_logging.c b/src/lib/util/common_logging.c
@@ -824,6 +824,11 @@ output_message (enum GNUNET_ErrorType kind,
{
static int have_journald = -1;
struct CustomLogger *pos;
+ char optional_newline = '\n';
+
+ if ((strlen (msg) > 0) &&
+ ('\n' == msg[strlen (msg) - 1]))
+ optional_newline = '\0';
if (-1 == have_journald)
{
@@ -868,33 +873,37 @@ output_message (enum GNUNET_ErrorType kind,
skip_log = 0;
if (have_journald)
fprintf (GNUNET_stderr,
- "(%s) %s %s",
+ "(%s) %s %s%c",
id_buf,
GNUNET_error_type_to_string (kind),
- msg);
+ msg,
+ optional_newline);
else
fprintf (GNUNET_stderr,
- "%s %s(%s) %s %s",
+ "%s %s(%s) %s %s%c",
datestr,
comp,
id_buf,
GNUNET_error_type_to_string (kind),
- msg);
+ msg,
+ optional_newline);
}
else
{
if (have_journald)
fprintf (GNUNET_stderr,
- "%s %s",
+ "%s %s%c",
GNUNET_error_type_to_string (kind),
- msg);
+ msg,
+ optional_newline);
else
fprintf (GNUNET_stderr,
- "%s %s %s %s",
+ "%s %s %s %s%c",
datestr,
comp,
GNUNET_error_type_to_string (kind),
- msg);
+ msg,
+ optional_newline);
}
fflush (GNUNET_stderr);
}