On Tue, Jun 24, 2025 at 10:00 AM Zhao Liu wrote:
>
> > /// A macro to log messages conditionally based on a provided mask.
> > @@ -24,6 +96,8 @@ pub enum Log {
> > /// log level and, if so, formats and logs the message. It is the Rust
> > /// counterpart of the `qemu_log_mask()` macro in the C
> > @@ -136,8 +137,7 @@ macro_rules! log_mask_ln {
> > if unsafe {
> > (::qemu_api::bindings::qemu_loglevel & ($mask as
> > std::os::raw::c_int)) != 0
> > } {
> > -#[allow(unused_must_use)]
> > -::qemu_api::log::LogGuard::log_fmt(
> > +
> +/// A RAII guard for QEMU's logging infrastructure. Creating the guard
> +/// locks the log file, and dropping it (letting it go out of scope) unlocks
> +/// the file.
> +///
> +/// As long as the guard lives, it can be written to using
> [`std::io::Write`].
> +///
> +/// The locking is recurs
> /// A macro to log messages conditionally based on a provided mask.
> @@ -24,6 +96,8 @@ pub enum Log {
> /// log level and, if so, formats and logs the message. It is the Rust
> /// counterpart of the `qemu_log_mask()` macro in the C implementation.
> ///
> +/// Errors from writing to the log
This makes it possible to lock the log file; it also makes log_mask_ln!
not allocate memory when logging a constant string.
Signed-off-by: Paolo Bonzini
---
include/qemu/log.h | 2 +
util/log.c | 12 ++
rust/qemu-api/src/log.rs | 87 --