From nobody Sun Sep 28 15:25:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758797724; cv=none; d=zohomail.com; s=zohoarc; b=nVBFE49sFjWchzPzfunQL4EJT/i2Vdxxb0Rt31fgCiP+p4av2OJEUlvIt1FHAH+KEJpNqjg+8EgG44UDqMOseZf122MGP5G4ddtjtNRx0bgdFBmH6bEDBUUw1aNQlF6nngwB7iFWjK83k4qfaJfA1HhgAyWS7wxQXgE9PZbH+gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758797724; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=mZJoRmH0LzYy4u3t3prpzh/NicjETYCxcryAx0u5eAw=; b=Rd7jjjRNLUbsxRYiqyDBfg49D7Uh7QC6wkgnFV2cjj/FKLaelWUrfpN/B2TWDDdmugL32cNtoHgJt96xIqXpK1N+pb3cGYk4DFPnf+WKxax3CYpScngRg2UBWd9wdhMHqs7Kp0ncBronHYfqxQ52ZDabDmUbg/c4IIGoue87QGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758797724217918.5245802978734; Thu, 25 Sep 2025 03:55:24 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 306974409C; Thu, 25 Sep 2025 06:55:23 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2A8F8443F3; Thu, 25 Sep 2025 05:49:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id D24BB43DE8; Thu, 25 Sep 2025 05:48:34 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4EBE441837 for ; Thu, 25 Sep 2025 05:46:41 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-orMQIbdsMvqdmttta_mbwg-1; Thu, 25 Sep 2025 05:46:36 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93B991956053; Thu, 25 Sep 2025 09:46:34 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10F3B300021A; Thu, 25 Sep 2025 09:46:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mZJoRmH0LzYy4u3t3prpzh/NicjETYCxcryAx0u5eAw=; b=I/DvQzaRejHcN4crhzatnb5zPtf05NSje4VsC2FSF/iQAbzI4yo5UnbdOITe9CATN+RJqJ tv9+KWL9MXm2M71so4X08McpgSoQJ+luqW9RM2Ju8EN6g8ylqIi9YKOinwX8hwTMD0HdLo EZWExg6AF694KGelIFg2kdDDhGtCMMM= X-MC-Unique: orMQIbdsMvqdmttta_mbwg-1 X-Mimecast-MFC-AGG-ID: orMQIbdsMvqdmttta_mbwg_1758793594 To: qemu-devel@nongnu.org Subject: [PATCH v4 18/23] util: introduce common helper for error-report & log code Date: Thu, 25 Sep 2025 10:44:36 +0100 Message-ID: <20250925094441.1651372-19-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Message-ID-Hash: ROFFKLAK2H5GQFDYDBDDPZSJVOMV6GDH X-Message-ID-Hash: ROFFKLAK2H5GQFDYDBDDPZSJVOMV6GDH X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758797726802116600 The error-report and log code both have a need to add prefixes to messages they are printing, with the current example being a timestamp. The format and configuration they use should be consistent, so providing a common helper will ensure this is always the case. Initially the helper only emits a timestamp, but future patches will expand this. This takes the liberty of assigning the new file to the same maintainer as the existing error-report.c file, given it will be extracting some functionality from the latter. While vreport() dynamically changes between reporting to the monitor vs stderr, depending on whether HMP is active or not, message prefixes are only ever used in the non-HMP case. Thus the helper API can take a FILE * object and not have to deal with the monitor at all. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 ++ include/qemu/message.h | 28 ++++++++++++++++++++++++++++ util/meson.build | 1 + util/message.c | 22 ++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 include/qemu/message.h create mode 100644 util/message.c diff --git a/MAINTAINERS b/MAINTAINERS index 24b71a4fc5..e128a9d3be 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3173,9 +3173,11 @@ M: Markus Armbruster S: Supported F: include/qapi/error.h F: include/qemu/error-report.h +F: include/qemu/message.h F: qapi/error.json F: util/error.c F: util/error-report.c +F: util/message.c F: scripts/coccinelle/err-bad-newline.cocci F: scripts/coccinelle/error-use-after-free.cocci F: scripts/coccinelle/error_propagate_null.cocci diff --git a/include/qemu/message.h b/include/qemu/message.h new file mode 100644 index 0000000000..0a06421f77 --- /dev/null +++ b/include/qemu/message.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef QEMU_MESSAGE_H +#define QEMU_MESSAGE_H + +enum QMessageFormatFlags { + QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), +}; + +/** + * qmessage_set_format: + * @flags: the message information to emit + * + * Select which pieces of information to + * emit for messages + */ +void qmessage_set_format(int flags); + +/** + * qmessage_context_print: + * @fp: file to emit the prefix on + * + * Emit a message prefix with the information selected by + * an earlier call to qmessage_set_format. + */ +void qmessage_context_print(FILE *fp); + +#endif /* QEMU_MESSAGE_H */ diff --git a/util/meson.build b/util/meson.build index 35029380a3..f5365e3b4f 100644 --- a/util/meson.build +++ b/util/meson.build @@ -40,6 +40,7 @@ util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheflush.c')) +util_ss.add(files('message.c')) util_ss.add(files('error.c', 'error-report.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c')) diff --git a/util/message.c b/util/message.c new file mode 100644 index 0000000000..643f10c06a --- /dev/null +++ b/util/message.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "qemu/message.h" +#include "monitor/monitor.h" + +static int message_format; + +void qmessage_set_format(int flags) +{ + message_format =3D flags; +} + +void qmessage_context_print(FILE *fp) +{ + if (message_format & QMESSAGE_FORMAT_TIMESTAMP) { + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + g_autofree char *timestr =3D g_date_time_format_iso8601(dt); + fprintf(fp, "%s ", timestr); + } +} --=20 2.50.1