CHARDEV_GET_CLASS(s)->chr_be_event(s, event);
}
-static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
+static void do_write_log(Chardev *s, const uint8_t *buf, size_t len)
{
- if (s->logfd < 0) {
- return;
- }
-
if (qemu_write_full(s->logfd, buf, len) < len) {
/*
* qemu_write_full() is defined with G_GNUC_WARN_UNUSED_RESULT,
}
}
+static void do_write_log_timestamps(Chardev *s, const uint8_t *buf, size_t len)
+{
+ g_autofree char *timestr = NULL;
+
+ while (len) {
+ size_t i;
+
+ if (s->log_line_start) {
+ if (!timestr) {
+ timestr = real_time_iso8601();
+ }
+ do_write_log(s, (const uint8_t *)timestr, strlen(timestr));
+ do_write_log(s, (const uint8_t *)" ", 1);
+ s->log_line_start = false;
+ }
+
+ for (i = 0; i < len; i++) {
+ if (buf[i] == '\n') {
+ break;
+ }
+ }
+
+ if (i == len) {
+ /* not found \n */
+ do_write_log(s, buf, len);
+ return;
+ }
+
+ i += 1;
+ do_write_log(s, buf, i);
+ buf += i;
+ len -= i;
+ s->log_line_start = true;
+ }
+}
+
+static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
+{
+ if (s->logfd < 0) {
+ return;
+ }
+
+ if (s->logtimestamp) {
+ do_write_log_timestamps(s, buf, len);
+ } else {
+ do_write_log(s, buf, len);
+ }
+}
+
static int qemu_chr_write_buffer(Chardev *s,
const uint8_t *buf, int len,
int *offset, bool write_all)
} else {
flags |= O_TRUNC;
}
+ chr->logtimestamp = common->has_logtimestamp && common->logtimestamp;
chr->logfd = qemu_create(common->logfile, flags, 0666, errp);
if (chr->logfd < 0) {
return false;
chr->handover_yank_instance = false;
chr->logfd = -1;
+ chr->log_line_start = true;
qemu_mutex_init(&chr->chr_write_lock);
/*
backend->logfile = g_strdup(logfile);
backend->has_logappend = true;
backend->logappend = qemu_opt_get_bool(opts, "logappend", false);
+
+ backend->has_logtimestamp = true;
+ backend->logtimestamp = qemu_opt_get_bool(opts, "logtimestamp", false);
}
static const ChardevClass *char_get_class(const char *driver, Error **errp)
},{
.name = "logappend",
.type = QEMU_OPT_BOOL,
+ },{
+ .name = "logtimestamp",
+ .type = QEMU_OPT_BOOL,
},{
.name = "mouse",
.type = QEMU_OPT_BOOL,