qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com
Subject: [RFC 4/4] util/error-report: Use LogOutput in vreport
Date: Tue,  2 Sep 2025 12:30:10 +0200	[thread overview]
Message-ID: <20250902103010.309094-5-richard.henderson@linaro.org> (raw)
In-Reply-To: <20250902103010.309094-1-richard.henderson@linaro.org>

Merge print_loc.  Use the LogOutput callbacks instead of
error_printf and error_vprintf.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/error-report.c | 72 +++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

diff --git a/util/error-report.c b/util/error-report.c
index 6ef556af5f..db5b2c1608 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -132,36 +132,6 @@ void loc_set_file(const char *fname, int lno)
     }
 }
 
-/*
- * Print current location to current monitor if we have one, else to stderr.
- */
-static void print_loc(void)
-{
-    const char *sep = "";
-    int i;
-    const char *const *argp;
-
-    switch (cur_loc->kind) {
-    case LOC_CMDLINE:
-        argp = cur_loc->ptr;
-        for (i = 0; i < cur_loc->num; i++) {
-            error_printf("%s%s", sep, argp[i]);
-            sep = " ";
-        }
-        error_printf(": ");
-        break;
-    case LOC_FILE:
-        error_printf("%s:", (const char *)cur_loc->ptr);
-        if (cur_loc->num) {
-            error_printf("%d:", cur_loc->num);
-        }
-        error_printf(" ");
-        break;
-    default:
-        error_printf("%s", sep);
-    }
-}
-
 /*
  * Print a message to current monitor if we have one, else to stderr.
  * @report_type is the type of message: error, warning or informational.
@@ -172,28 +142,54 @@ static void print_loc(void)
 G_GNUC_PRINTF(2, 0)
 static void vreport(report_type type, const char *fmt, va_list ap)
 {
-    if (!monitor_cur()) {
-        void *opaque;
-        const LogOutput *l = error_log_output(&opaque);
+    void *opaque;
+    const LogOutput *l = error_log_output(&opaque);
 
+    if (!monitor_cur()) {
         qmessage_context(l, opaque);
     }
 
-    print_loc();
+    switch (cur_loc->kind) {
+    case LOC_CMDLINE:
+        {
+            const char *const *argp = cur_loc->ptr;
+            const char *sep = "";
+
+            for (int i = 0; i < cur_loc->num; i++) {
+                l->print(opaque, "%s%s", sep, argp[i]);
+                sep = " ";
+            }
+            l->print(opaque, ": ");
+        }
+        break;
+    case LOC_FILE:
+        {
+            const char *file = cur_loc->ptr;
+
+            if (cur_loc->num) {
+                error_printf("%s:%d: ", file, cur_loc->num);
+            } else {
+                error_printf("%s: ", file);
+            }
+        }
+        break;
+    case LOC_NONE:
+        break;
+    }
 
     switch (type) {
     case REPORT_TYPE_ERROR:
         break;
     case REPORT_TYPE_WARNING:
-        error_printf("warning: ");
+        l->print(opaque, "warning: ");
         break;
     case REPORT_TYPE_INFO:
-        error_printf("info: ");
+        l->print(opaque, "info: ");
         break;
     }
 
-    error_vprintf(fmt, ap);
-    error_printf("\n");
+    l->vprint(opaque, fmt, ap);
+    l->print(opaque, "\n");
 }
 
 /*
-- 
2.43.0



  parent reply	other threads:[~2025-09-02 10:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 10:30 [RFC 0/4] util: qmessage_context followup Richard Henderson
2025-09-02 10:30 ` [RFC 1/4] util: Introduce LogOutput Richard Henderson
2025-09-02 10:30 ` [RFC 2/4] util: Drop QMESSAGE_CONTEXT_SKIP_MONITOR Richard Henderson
2025-09-02 10:30 ` [RFC 3/4] util/message: Use LogOutput Richard Henderson
2025-09-02 10:30 ` Richard Henderson [this message]
2025-09-02 16:47 ` [RFC 0/4] util: qmessage_context followup Daniel P. Berrangé
2025-09-10 18:05 ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250902103010.309094-5-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).