From 765f80f9ba5d164945cff12e2905d3ab2a0d6fa2 Mon Sep 17 00:00:00 2001 From: yoav Date: Thu, 21 Nov 2019 10:19:12 +0200 Subject: [PATCH] Fix LoggingHandler time conversion Current version covert it to wrong time(offset of local time was added to epoch). In additon ms are now included. --- logbook/compat.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/logbook/compat.py b/logbook/compat.py index 602a11a..98018f8 100644 --- a/logbook/compat.py +++ b/logbook/compat.py @@ -9,17 +9,15 @@ :copyright: (c) 2010 by Armin Ronacher, Georg Brandl. :license: BSD, see LICENSE for more details. """ -import collections +import time import logging import sys import warnings -from datetime import date, datetime +from datetime import datetime import logbook from logbook.helpers import u, string_types, iteritems, collections_abc -_epoch_ord = date(1970, 1, 1).toordinal() - def redirect_logging(set_root_logger_level=True): """Permanently redirects logging to the stdlib. This also @@ -193,12 +191,7 @@ def convert_level(self, level): def convert_time(self, dt): """Converts a datetime object into a timestamp.""" - year, month, day, hour, minute, second = dt.utctimetuple()[:6] - days = date(year, month, 1).toordinal() - _epoch_ord + day - 1 - hours = days * 24 + hour - minutes = hours * 60 + minute - seconds = minutes * 60 + second - return seconds + return time.mktime(dt.timetuple()) + dt.microsecond / 1E6 def convert_record(self, old_record): """Converts a record from logbook to logging."""