log/template

This commit is contained in:
Marc Beninca 2024-09-13 19:24:11 +02:00
parent 78dd431ca5
commit bf1b3402ae
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -7,9 +7,14 @@ import sys
def get_file_logger(name: str) -> logging.Logger: def get_file_logger(name: str) -> logging.Logger:
"""Return a file logger.""" """Return a file logger."""
# formatter # formatter
formatter = logging.Formatter( items = [
"%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", "%(name)s: %(asctime)s",
) "%(levelname)s",
"%(filename)s:%(lineno)s",
"%(process)d >>> %(message)s",
]
template = " | ".join(items)
formatter = logging.Formatter(template)
# handler # handler
out_handler = logging.StreamHandler(stream=sys.stdout) out_handler = logging.StreamHandler(stream=sys.stdout)
out_handler.setFormatter(formatter) out_handler.setFormatter(formatter)