From 391517658ffbc8190b800b131ab54db614a88768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sat, 19 Jun 2021 19:25:45 +0000 Subject: [PATCH] Handle lowres timestamps --- logger.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/logger.py b/logger.py index 1811850..c769ea8 100755 --- a/logger.py +++ b/logger.py @@ -33,9 +33,13 @@ class Server(object): async def _handle_request(self, obj, writer: asyncio.StreamWriter) -> None: tag, time, record, options = obj - seconds, nanoseconds = struct.unpack(">II", time.data) + try: + seconds, nanoseconds = struct.unpack(">II", time.data) + record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds/1000)) + except AttributeError: + record["time"] = datetime.fromtimestamp(time) assert not options, "Can't handle options" - record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds/1000)) + record.pop("container_id", None) record["host"] = FQDN result = await db.log.insert_one(record)