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.
This commit is contained in:
parent
ad2f08e89b
commit
c6b2077263
@ -8,6 +8,8 @@ from i3pystatus.core.exceptions import ConfigError
|
|||||||
from i3pystatus.core.imputil import ClassFinder
|
from i3pystatus.core.imputil import ClassFinder
|
||||||
from i3pystatus.core.modules import Module
|
from i3pystatus.core.modules import Module
|
||||||
|
|
||||||
|
DEFAULT_LOG_FORMAT = '%(asctime)s [%(levelname)-8s][%(name)s %(lineno)d] %(message)s'
|
||||||
|
|
||||||
|
|
||||||
class CommandEndpoint:
|
class CommandEndpoint:
|
||||||
"""
|
"""
|
||||||
@ -59,17 +61,21 @@ class Status:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, standalone=True, click_events=True, interval=1,
|
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.standalone = standalone
|
||||||
self.click_events = standalone and click_events
|
self.click_events = standalone and click_events
|
||||||
input_stream = input_stream or sys.stdin
|
input_stream = input_stream or sys.stdin
|
||||||
|
logger = logging.getLogger("i3pystatus")
|
||||||
if logfile:
|
if logfile:
|
||||||
logger = logging.getLogger("i3pystatus")
|
|
||||||
for handler in logger.handlers:
|
for handler in logger.handlers:
|
||||||
logger.removeHandler(handler)
|
logger.removeHandler(handler)
|
||||||
handler = logging.FileHandler(logfile, delay=True)
|
handler = logging.FileHandler(logfile, delay=True)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
logger.setLevel(logging.CRITICAL)
|
logger.setLevel(logging.CRITICAL)
|
||||||
|
if logformat:
|
||||||
|
for index in range(len(logger.handlers)):
|
||||||
|
logger.handlers[index].setFormatter(logging.Formatter(logformat))
|
||||||
if internet_check:
|
if internet_check:
|
||||||
util.internet.address = internet_check
|
util.internet.address = internet_check
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user