[PATCH 2/4] virsh: Add timestamps to events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A new --timestamp option for event virsh command can be used to print
timestamp of each event.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 tools/virsh-domain.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ba38ed9..6e219de 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12137,6 +12137,7 @@ struct virshDomEventData {
     vshControl *ctl;
     bool loop;
     int *count;
+    bool timestamp;
     vshEventCallback *cb;
     int id;
 };
@@ -12154,7 +12155,16 @@ virshEventPrint(virshDomEventData *data,
     if (!data->loop && *data->count)
         goto cleanup;
 
-    vshPrint(data->ctl, "%s", msg);
+    if (data->timestamp) {
+        char timestamp[VIR_TIME_STRING_BUFLEN];
+
+        if (virTimeStringNowRaw(timestamp) < 0)
+            timestamp[0] = '\0';
+
+        vshPrint(data->ctl, "%s: %s", timestamp, msg);
+    } else {
+        vshPrint(data->ctl, "%s", msg);
+    }
 
     (*data->count)++;
     if (!data->loop)
@@ -12533,6 +12543,10 @@ static const vshCmdOptDef opts_event[] = {
      .type = VSH_OT_BOOL,
      .help = N_("list valid event types")
     },
+    {.name = "timestamp",
+     .type = VSH_OT_BOOL,
+     .help = N_("show timestamp for each printed event")
+    },
     {.name = NULL}
 };
 
@@ -12548,6 +12562,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
     int event = -1;
     bool all = vshCommandOptBool(cmd, "all");
     bool loop = vshCommandOptBool(cmd, "loop");
+    bool timestamp = vshCommandOptBool(cmd, "timestamp");
     int count = 0;
     virshControlPtr priv = ctl->privData;
 
@@ -12580,6 +12595,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
             data[i].ctl = ctl;
             data[i].loop = loop;
             data[i].count = &count;
+            data[i].timestamp = timestamp;
             data[i].cb = &vshEventCallbacks[i];
             data[i].id = -1;
         }
@@ -12589,6 +12605,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
         data[0].ctl = ctl;
         data[0].loop = vshCommandOptBool(cmd, "loop");
         data[0].count = &count;
+        data[0].timestamp = timestamp;
         data[0].cb = &vshEventCallbacks[event];
         data[0].id = -1;
     }
-- 
2.6.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]