From 6b1641c4387e20c33318bcd8c3566541ddebe853 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 5 Aug 2018 12:13:25 +0100 Subject: Put milliseconds in logging.py --- modules/logging.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'modules/logging.py') diff --git a/modules/logging.py b/modules/logging.py index 3e2aa65d..4876741b 100644 --- a/modules/logging.py +++ b/modules/logging.py @@ -1,13 +1,26 @@ -import logging, sys +import logging, sys, time + +class BitBotFormatter(logging.Formatter): + def formatTime(self, record, datefmt=None): + ct = self.converter(record.created) + if datefmt: + if "%f" in datefmt: + msec = "%03d" % record.msecs + datefmt = datefmt.replace("%f", msec) + s = time.strftime(datefmt, ct) + else: + t = time.strftime("%Y-%m-%d %H:%M:%S", ct) + s = "%s.%03d" % (t, record.msecs) + return s class Module(object): def __init__(self, bot): self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) - formatter = logging.Formatter( + formatter = BitBotFormatter( "%(asctime)s - %(levelname)s - %(message)s", - "%Y-%m-%dT%H:%M:%S%z") + "%Y-%m-%dT%H:%M:%S.%f%z") stdout_handler = logging.StreamHandler(sys.stdout) stdout_handler.setLevel(logging.INFO) -- cgit v1.3.1-10-gc9f91