diff options
author | Kerim Gokarslan <kgokarsl@cisco.com> | 2017-09-06 10:14:12 -0700 |
---|---|---|
committer | Kerim Gokarslan <kgokarsl@cisco.com> | 2017-09-06 10:14:12 -0700 |
commit | 46f94badf4feadcf64f57071d99f7ccd86f19ed9 (patch) | |
tree | 56edafe42695b845fbcee1ffa7b886d4158b0b3c | |
parent | a63d257a7b2cdbf18626d9963ac188317cf768b7 (diff) |
NFVBENCH-18 Add microsecond precision to fluentd records1.0.5
Change-Id: If6d2af11355d2d2cefb4b5098e912d98d2043e32
Signed-off-by: Kerim Gokarslan <kgokarsl@cisco.com>
-rw-r--r-- | nfvbench/fluentd.py | 14 |
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") |