diff options
| author | 2018-08-05 12:13:25 +0100 | |
|---|---|---|
| committer | 2018-08-05 12:13:25 +0100 | |
| commit | 6b1641c4387e20c33318bcd8c3566541ddebe853 (patch) | |
| tree | fd35e3ed21ddc80cd34c324f154d15943c6e8a9a /modules | |
| parent | Actually add event hook for CRITICAL (diff) | |
| signature | ||
Put milliseconds in logging.py
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/logging.py | 19 |
1 files changed, 16 insertions, 3 deletions
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) |
