def format(self, record):
""" Formats the record.msg string by using click.style()
The record will have attributes set to it when a user logs a message
with any kwargs given. This function looks for any attributes that
are in STYLES. If record has any sytle attributes, the record will
be styled with the given sytle. This makes click logging with a logger very easy.
Args:
record (logging.LogRecord): record which gets styled with click.style()
"""
# Sets the default kwargs
kwargs = dict()
# checks if any click args were passed along in the logger
for kwarg_name in self.STYLES:
if hasattr(record, kwarg_name):
kwargs[kwarg_name] = getattr(record, kwarg_name)
# styles the message of the record if a style was given
if kwargs:
record.msg = click.style(record.msg, **kwargs)
return record
评论列表
文章目录