virRotatingFileWriterAppendTimestamp function appends timestamp to a
file.
Signed-off-by: Shaleen Bathla <shaleen.bathla(a)oracle.com>
---
src/util/virrotatingfile.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index b02a88c4b08d..2a44c9bf93e3 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -30,6 +30,7 @@
#include "virerror.h"
#include "virfile.h"
#include "virlog.h"
+#include "virtime.h"
VIR_LOG_INIT("util.rotatingfile");
@@ -406,6 +407,40 @@ virRotatingFileWriterRollover(virRotatingFileWriter *file)
}
+/**
+ * virRotatingFileWriterAppendTimestamp:
+ * @file: the file context
+ *
+ * Append current timestamp with a trailing ' ' char to @file
+ *
+ * Returns 0 on success and -1 on error
+ */
+static ssize_t
+virRotatingFileWriterAppendTimestamp(virRotatingFileWriter* file)
+{
+ char* timestamp = NULL;
+ size_t len = 0;
+
+ if (!(timestamp = virTimeStringNow())) {
+ g_free(timestamp);
+ return -1;
+ }
+
+ len = VIR_TIME_STRING_BUFLEN;
+ timestamp = g_realloc(timestamp, len+1);
+ timestamp[len-1] = ' ';
+ timestamp[len] = '\0';
+
+ if (virRotatingFileWriterAppend(file, timestamp, len) != len) {
+ g_free(timestamp);
+ return -1;
+ }
+
+ g_free(timestamp);
+ return 0;
+}
+
+
/**
* virRotatingFileWriterAppend:
* @file: the file context
--
2.39.3