aboutsummaryrefslogtreecommitdiff
path: root/util/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/log.c')
-rw-r--r--util/log.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/util/log.c b/util/log.c
index b87d399..abdcb6b 100644
--- a/util/log.c
+++ b/util/log.c
@@ -145,10 +145,28 @@ void qemu_log_unlock(FILE *logfile)
void qemu_log(const char *fmt, ...)
{
- FILE *f = qemu_log_trylock();
+ FILE *f;
+ g_autofree const char *timestr = NULL;
+
+ /*
+ * Prepare the timestamp *outside* the logging
+ * lock so it better reflects when the message
+ * was emitted if we are delayed acquiring the
+ * mutex
+ */
+ if (message_with_timestamp) {
+ g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
+ timestr = g_date_time_format_iso8601(dt);
+ }
+
+ f = qemu_log_trylock();
if (f) {
va_list ap;
+ if (timestr) {
+ fprintf(f, "%s ", timestr);
+ }
+
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
@@ -558,3 +576,15 @@ void qemu_print_log_usage(FILE *f)
fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n");
#endif
}
+
+#ifdef CONFIG_HAVE_RUST
+ssize_t rust_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+ /*
+ * Same as fwrite, but return -errno because Rust libc does not provide
+ * portable access to errno. :(
+ */
+ int ret = fwrite(ptr, size, nmemb, stream);
+ return ret < 0 ? -errno : 0;
+}
+#endif