* [PATCH] log: Don't prefix log file messages with time and severity if they're continuations
@ 2024-09-04 14:29 Stefano Brivio
2024-09-05 0:27 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2024-09-04 14:29 UTC (permalink / raw)
To: passt-dev; +Cc: AbdAlRahman Gad
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>
---
log.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/log.c b/log.c
index 433b552..a61468e 100644
--- a/log.c
+++ b/log.c
@@ -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);
--
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] log: Don't prefix log file messages with time and severity if they're continuations
2024-09-04 14:29 [PATCH] log: Don't prefix log file messages with time and severity if they're continuations Stefano Brivio
@ 2024-09-05 0:27 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2024-09-05 0:27 UTC (permalink / raw)
To: Stefano Brivio; +Cc: passt-dev, AbdAlRahman Gad
[-- Attachment #1: Type: text/plain, Size: 2476 bytes --]
On Wed, Sep 04, 2024 at 04:29:57PM +0200, Stefano Brivio wrote:
> 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>
> ---
> log.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/log.c b/log.c
> index 433b552..a61468e 100644
> --- a/log.c
> +++ b/log.c
> @@ -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);
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-05 0:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 14:29 [PATCH] log: Don't prefix log file messages with time and severity if they're continuations Stefano Brivio
2024-09-05 0:27 ` David Gibson
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).