added some rich logging

This commit is contained in:
John Lancaster
2024-03-03 14:54:11 -06:00
parent d8a9d3d83a
commit 215d47ea00
3 changed files with 97 additions and 79 deletions

20
console.py Normal file
View File

@@ -0,0 +1,20 @@
from appdaemon.adapi import ADAPI
from rich.console import Console
from rich.logging import RichHandler
console = Console(width=150)
handler = RichHandler(
console=console,
markup=True,
show_path=False,
log_time_format='%Y-%m-%d %I:%M:%S %p',
)
def setup_logging(self: ADAPI):
if not any(isinstance(h, RichHandler) for h in self.logger.handlers):
self.logger.propagate = False
self.logger.addHandler(handler)
self.log(f'Added rich handler for [bold green]{self.logger.name}[/]')
self.log(f'Formatter [bold green]{self.logger.handlers[0].formatter}[/]')