From c6b20772639bd3a0342a4db86920721490c4f733 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Mon, 4 Apr 2016 13:22:02 -0500 Subject: [PATCH] Add support for logformat parameter to i3pystatus.Status() This improves the usefulness of log messages, especially when it comes to debug logging added for the purpose of future troubleshooting. --- i3pystatus/core/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/i3pystatus/core/__init__.py b/i3pystatus/core/__init__.py index 4bd54a6..1c0a9d1 100644 --- a/i3pystatus/core/__init__.py +++ b/i3pystatus/core/__init__.py @@ -8,6 +8,8 @@ from i3pystatus.core.exceptions import ConfigError from i3pystatus.core.imputil import ClassFinder from i3pystatus.core.modules import Module +DEFAULT_LOG_FORMAT = '%(asctime)s [%(levelname)-8s][%(name)s %(lineno)d] %(message)s' + class CommandEndpoint: """ @@ -59,17 +61,21 @@ class Status: """ def __init__(self, standalone=True, click_events=True, interval=1, - input_stream=None, logfile=None, internet_check=None): + input_stream=None, logfile=None, internet_check=None, + logformat=DEFAULT_LOG_FORMAT): self.standalone = standalone self.click_events = standalone and click_events input_stream = input_stream or sys.stdin + logger = logging.getLogger("i3pystatus") if logfile: - logger = logging.getLogger("i3pystatus") for handler in logger.handlers: logger.removeHandler(handler) handler = logging.FileHandler(logfile, delay=True) logger.addHandler(handler) logger.setLevel(logging.CRITICAL) + if logformat: + for index in range(len(logger.handlers)): + logger.handlers[index].setFormatter(logging.Formatter(logformat)) if internet_check: util.internet.address = internet_check