1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-6.git synced 2024-11-21 23:44:19 +00:00

Allow registration of multiple custom loggers

This commit is contained in:
Steffo 2023-02-02 04:36:55 +01:00
parent ab5f12f8fc
commit b347031663
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -4,30 +4,34 @@ import coloredlogs
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def install_log_handler(logger: logging.Logger = None): def install_log_handler(loggers: list[logging.Logger] = None):
if logger is None: if loggers is None:
logger = logging.getLogger("unimore_bda_6") loggers = [
logging.getLogger("__main__"),
logging.getLogger("unimore_bda_6"),
]
coloredlogs.install( for logger in loggers:
logger=logger, coloredlogs.install(
level="DEBUG", logger=logger,
fmt="{asctime} | {name:<32} | {levelname:>8} | {message}", level="DEBUG",
style="{", fmt="{asctime} | {name:<32} | {levelname:>8} | {message}",
level_styles=dict( style="{",
debug=dict(color="white"), level_styles=dict(
info=dict(color="cyan"), debug=dict(color="white"),
warning=dict(color="yellow"), info=dict(color="cyan"),
error=dict(color="red"), warning=dict(color="yellow"),
critical=dict(color="red", bold=True), error=dict(color="red"),
), critical=dict(color="red", bold=True),
field_styles=dict( ),
asctime=dict(color='magenta'), field_styles=dict(
levelname=dict(color='blue', bold=True), asctime=dict(color='magenta'),
name=dict(color='blue'), levelname=dict(color='blue', bold=True),
), name=dict(color='blue'),
isatty=True, ),
) isatty=True,
log.info("Installed custom log handler!") )
log.debug("Installed custom log handler on: %s", logger)
__all__ = ( __all__ = (