From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Eric Blake" <eblake@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>
Subject: [PATCH 18/21] log: enable directing log messages to data recorder
Date: Thu, 15 Oct 2026 12:20:41 +0100 [thread overview]
Message-ID: <20261015112044.1999748-19-berrange@redhat.com> (raw)
In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com>
Currently the log APIs can output messages to stderr, a named
loge file, or discarded to /dev/null. Introduce a "tldr" log
mask category which causes log messages to be directed to the
data recorder.
This this output is mutually exclusive with file based logging
and only captures single line logs emitted with qemu_log() or
qemu_log_mask(). Log callers using direct FILE* access will be
discarded. This is sufficient for the primary intended use case
which is to collect output from the 'log' trace backend.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/qemu/log.h | 1 +
util/log.c | 42 +++++++++++++++++++++++++++++++++---------
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 92956e5d0f5..47d89681d8e 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -38,6 +38,7 @@ bool qemu_log_separate(void);
#define CPU_LOG_TB_VPU (1u << 21)
#define LOG_TB_OP_PLUGIN (1u << 22)
#define LOG_INVALID_MEM (1u << 23)
+#define LOG_TLDR (1u << 24)
/* Lock/unlock output. */
diff --git a/util/log.c b/util/log.c
index 7cffbc1bf89..df7499012f6 100644
--- a/util/log.c
+++ b/util/log.c
@@ -27,6 +27,7 @@
#include "qemu/thread.h"
#include "qemu/lockable.h"
#include "qemu/rcu.h"
+#include "qemu/tldr.h"
#ifdef CONFIG_LINUX
#include <sys/syscall.h>
#endif
@@ -172,12 +173,20 @@ void qemu_log_unlock(FILE *logfile)
void qemu_log(const char *fmt, ...)
{
- FILE *f = qemu_log_trylock_with_context();
- if (f) {
- va_list ap;
- va_start(ap, fmt);
- vfprintf(f, fmt, ap);
- va_end(ap);
+ va_list ap;
+ if (qemu_loglevel & LOG_TLDR) {
+ if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_LOG)) {
+ va_start(ap, fmt);
+ qtldr_msg_record_vprintf(QTLDR_MSG_BUCKET_TYPE_LOG, fmt, ap);
+ va_end(ap);
+ }
+ } else {
+ FILE *f = qemu_log_trylock_with_context();
+ if (f) {
+ va_start(ap, fmt);
+ vfprintf(f, fmt, ap);
+ va_end(ap);
+ }
qemu_log_unlock(f);
}
}
@@ -236,6 +245,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name,
bool need_to_open_file;
bool daemonized;
bool per_thread;
+ bool tldr;
FILE *logfile;
QEMU_LOCK_GUARD(&global_mutex);
@@ -251,8 +261,20 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name,
}
per_thread = log_flags & LOG_PER_THREAD;
+ tldr = log_flags & LOG_TLDR;
- if (changed_name) {
+ if (tldr) {
+ if (filename) {
+ error_setg(errp, "Cannot enable TLDR with a log file");
+ return false;
+ }
+ if (per_thread) {
+ error_setg(errp, "Cannot enable TLDR with per-thread log files");
+ return false;
+ }
+ }
+
+ if (changed_name && !tldr) {
char *newname = NULL;
/*
@@ -282,7 +304,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name,
g_free(global_filename);
global_filename = newname;
filename = newname;
- } else {
+ } else if (!tldr) {
filename = global_filename;
if (per_thread &&
valid_filename_template(filename, true, errp) == vft_error) {
@@ -309,7 +331,7 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name,
* stderr or to a file (if there is a filename).
* If per-thread, open the file for each thread in qemu_log_trylock().
*/
- need_to_open_file = qemu_loglevel && !log_per_thread;
+ need_to_open_file = qemu_loglevel && !log_per_thread && !tldr;
} else {
/*
* If we are daemonized, we will only log if there is a filename.
@@ -531,6 +553,8 @@ const QEMULogItem qemu_log_items[] = {
"include VPU registers in the 'cpu' logging" },
{ LOG_INVALID_MEM, "invalid_mem",
"log invalid memory accesses" },
+ { LOG_TLDR, "tldr",
+ "log to QEMU data recorder instead ofa file" },
{ 0, NULL, NULL },
};
--
2.56.0
next prev parent reply other threads:[~2026-10-15 11:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 11:20 [PATCH 00/21] system: introduce a live data recorder facility Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 01/21] osdep: add 'ignore_value(x)' macro Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 02/21] system: move SIGBUS signal handling to signal.c Daniel P. Berrangé
2026-10-15 12:15 ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 03/21] system: rename qemu_init_sigbus to qemu_init_crash_signals Daniel P. Berrangé
2026-10-15 12:15 ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 04/21] system: run SIGBUS handler on alternate signal stack Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 05/21] util: expand alternate signal stack to all threads Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 06/21] osdep: provide dummy siginfo_t definition Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 09/21] system: trigger TLDR crash dump on unhandled SIGBUS Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 10/21] system: simplify signal handler logic Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 11/21] main: allow SIGBUS in the main loop Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 12/21] system: enable SIGBUS handling on non-Linux platforms Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 13/21] system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 14/21] util: introduce capture of textual messages in data recorder Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 15/21] util: capture warnings and errors in the " Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 16/21] monitor: remove obsolete/redundant exports Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 17/21] monitor: capture monitor commands and events in data recorder Daniel P. Berrangé
2026-10-15 15:57 ` Dr. David Alan Gilbert
2026-10-15 16:11 ` Daniel P. Berrangé
2026-10-15 11:20 ` Daniel P. Berrangé [this message]
2026-10-15 11:20 ` [PATCH 19/21] tests/qtest: add API to declare an expected crash signal Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 20/21] qtest: add 'crash' command to generate 'authentic' process crashes Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 21/21] tests/qtest: add test to validate data recorder on crashes Daniel P. Berrangé
2026-10-15 12:15 ` [PATCH 00/21] system: introduce a live data recorder facility marcandre.lureau
2026-10-15 12:32 ` Daniel P. Berrangé
2026-10-15 17:34 ` Pierrick Bouvier
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=20261015112044.1999748-19-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=eblake@redhat.com \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.