diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2024-09-03 23:45:53 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-09-06 12:52:21 +0200 |
commit | 0ea60e5a7741658ad7056a0a6674e00e72d2d288 (patch) | |
tree | 02568083f6a7aee9e1ea84eefe35b7fdf66c61fb | |
parent | 38363964fc96008761195984c989b036227e0e5c (diff) | |
download | passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar.gz passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar.bz2 passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar.lz passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar.xz passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.tar.zst passt-0ea60e5a7741658ad7056a0a6674e00e72d2d288.zip |
log: Don't prefix log file messages with time and severity if they're continuations
In fecb1b65b1ac ("log: Don't prefix message with timestamp on --debug
if it's a continuation"), I fixed this for --debug on standard error,
but not for log files: if messages are continuations, they shouldn't
be prefixed by timestamp and severity.
Otherwise, we'll print stuff like this:
0.0028: ERROR: Receive error on guest connection, reset0.0028: ERROR: : Bad file descriptor
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | log.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -224,19 +224,23 @@ static int logfile_rotate(int fd, const struct timespec *now) /** * logfile_write() - Write entry to log file, trigger rotation if full * @newline: Append newline at the end of the message, if missing + * @cont: Continuation of a previous message, on the same line * @pri: Facility and level map, same as priority for vsyslog() * @now: Timestamp * @format: Same as vsyslog() format * @ap: Same as vsyslog() ap */ -static void logfile_write(bool newline, int pri, const struct timespec *now, +static void logfile_write(bool newline, bool cont, int pri, + const struct timespec *now, const char *format, va_list ap) { char buf[BUFSIZ]; - int n; + int n = 0; - n = logtime_fmt(buf, BUFSIZ, now); - n += snprintf(buf + n, BUFSIZ - n, ": %s", logfile_prefix[pri]); + if (!cont) { + n += logtime_fmt(buf, BUFSIZ, now); + n += snprintf(buf + n, BUFSIZ - n, ": %s", logfile_prefix[pri]); + } n += vsnprintf(buf + n, BUFSIZ - n, format, ap); @@ -278,7 +282,7 @@ void vlogmsg(bool newline, bool cont, int pri, const char *format, va_list ap) va_copy(ap2, ap); /* Don't clobber ap, we need it again */ if (log_file != -1) - logfile_write(newline, pri, now, format, ap2); + logfile_write(newline, cont, pri, now, format, ap2); else if (!(log_mask & LOG_MASK(LOG_DEBUG))) passt_vsyslog(newline, pri, format, ap2); |