From 6b46b01fcb5e9468a998676390295b949456a2a5 Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 19 Feb 2020 09:50:40 +0100 Subject: [PATCH] Include time in log messages --- radicale/log.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/radicale/log.py b/radicale/log.py index 22531e67..21526a5e 100644 --- a/radicale/log.py +++ b/radicale/log.py @@ -39,7 +39,8 @@ except ImportError: systemd = None LOGGER_NAME = "radicale" -LOGGER_FORMAT = "[%(ident)s] %(levelname)s: %(message)s" +LOGGER_FORMAT = "[%(asctime)s] [%(ident)s] [%(levelname)s] %(message)s" +DATE_FORMAT = "%Y-%m-%d %H:%M:%S %z" logger = logging.getLogger(LOGGER_NAME) @@ -61,7 +62,7 @@ class IdentLogRecordFactory: def __call__(self, *args, **kwargs): record = self.upstream_factory(*args, **kwargs) - ident = "%x" % os.getpid() + ident = "%d" % os.getpid() main_thread = threading.main_thread() current_thread = threading.current_thread() if current_thread.name and main_thread != current_thread: @@ -135,7 +136,8 @@ def setup(): """Set global logging up.""" global register_stream handler = ThreadStreamsHandler(sys.stderr, get_default_handler()) - logging.basicConfig(format=LOGGER_FORMAT, handlers=[handler]) + logging.basicConfig(format=LOGGER_FORMAT, datefmt=DATE_FORMAT, + handlers=[handler]) register_stream = handler.register_stream log_record_factory = IdentLogRecordFactory(logging.getLogRecordFactory()) logging.setLogRecordFactory(log_record_factory)