Charles Short 2d8d3e9a3f Use python standard logging
Make the UI consistent by using python standarized logging everywhere.

Also log to the systemd-journald service so the logs are kept
around when a user deploys a newer version of a branch.

Story: 2010867
Task: 48556

Change-Id: I9f203dd6d3e0e17c0563f59efd5f4fa003fa030e
Signed-off-by: Charles Short <charles.short@windriver.com>
2023-10-23 14:02:10 -04:00

39 lines
1.0 KiB
Python

"""
Copyright (c) 2023 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
import logging
from rich.console import Console
from rich.logging import RichHandler
from systemd.journal import JournalHandler
def setup_log(debug=False):
level = logging.DEBUG if debug else logging.INFO
fmt = "%(message)s"
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.NOTSET)
journald_handler = JournalHandler(
SYSLOG_IDENTIFIER="apt-ostree")
journald_handler.setLevel(level)
journald_handler.setFormatter(logging.Formatter(
'[%(levelname)s] %(message)s'))
rootLogger.addHandler(journald_handler)
console = Console(highlight=False)
rich_handler = RichHandler(show_path=False,
show_time=False,
show_level=False,
console=console)
rich_handler.setLevel(level)
rich_handler.setFormatter(logging.Formatter(fmt))
rootLogger.addHandler(rich_handler)
return rootLogger