def formatter(formatter, update_custom_handlers=False):
"""
Set the formatter for all handlers of the default logger (``logzero.logger``).
This reconfigures only the logzero internal handlers by default, but you can also
reconfigure custom handlers by using ``update_custom_handlers=True``.
Beware that setting a formatter which uses colors also may write the color codes
to logfiles.
:arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
:arg bool update_custom_handlers: If you added custom handlers to this logger and want this to update them too, you need to set ``update_custom_handlers`` to `True`
"""
for handler in list(logger.handlers):
if hasattr(handler, LOGZERO_INTERNAL_LOGGER_ATTR) or update_custom_handlers:
handler.setFormatter(formatter)
global _formatter
_formatter = formatter
评论列表
文章目录