summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nfvbench/fluentd.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/nfvbench/fluentd.py b/nfvbench/fluentd.py
index 5bfcebe..06745ca 100644
--- a/nfvbench/fluentd.py
+++ b/nfvbench/fluentd.py
@@ -15,6 +15,7 @@
from datetime import datetime
from fluent import sender
import logging
+import pytz
class FluentLogHandler(logging.Handler):
@@ -51,7 +52,8 @@ class FluentLogHandler(logging.Handler):
data = {
"runlogdate": self.runlogdate,
"loglevel": record.levelname,
- "message": self.formatter.format(record)
+ "message": self.formatter.format(record),
+ "@timestamp": self.__get_timestamp()
}
self.__update_stats(record.levelno)
self.sender.emit(None, data)
@@ -64,7 +66,8 @@ class FluentLogHandler(logging.Handler):
"message": "NFVBENCH run is started",
"numloglevel": 0,
"numerrors": 0,
- "numwarnings": 0
+ "numwarnings": 0,
+ "@timestamp": self.__get_timestamp()
}
self.sender.emit(None, data)
@@ -77,7 +80,8 @@ class FluentLogHandler(logging.Handler):
"message": self.__get_highest_level_desc(),
"numloglevel": self.__get_highest_level(),
"numerrors": self.__error_counter,
- "numwarnings": self.__warning_counter
+ "numwarnings": self.__warning_counter,
+ "@timestamp": self.__get_timestamp()
}
self.sender.emit(None, data)
@@ -102,3 +106,7 @@ class FluentLogHandler(logging.Handler):
self.__warning_counter += 1
elif levelno == logging.ERROR:
self.__error_counter += 1
+
+ def __get_timestamp(self):
+ return datetime.utcnow().replace(tzinfo=pytz.utc).strftime(
+ "%Y-%m-%dT%H:%M:%S.%f%z")