button work

This commit is contained in:
John Lancaster
2024-03-06 20:17:38 -06:00
parent 0939c21554
commit 17670b983e
4 changed files with 40 additions and 15 deletions

View File

@@ -1,26 +1,39 @@
import logging
from appdaemon.adapi import ADAPI
from appdaemon.logging import AppNameFormatter
from rich.console import Console
from rich.highlighter import NullHighlighter
from rich.logging import RichHandler
from rich.theme import Theme
console = Console(
width=150,
theme=Theme({'appname': 'italic bright_cyan'}),
)
console = Console(width=150)
handler = RichHandler(
console=console,
highlighter=NullHighlighter(),
markup=True,
show_path=False,
omit_repeated_times=False,
log_time_format='%Y-%m-%d %I:%M:%S %p',
)
def setup_logging(self: ADAPI, level):
handler.setFormatter(AppNameFormatter(fmt='[appname]{appname}[/] {message}', style='{'))
def init_logging(self: ADAPI, level):
if not any(isinstance(h, RichHandler) for h in self.logger.handlers):
self.logger.propagate = False
self.logger.setLevel(level)
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}[/]')
# self.log(f'Formatter for RichHandler: {handler.formatter}')
def deinit_logging(self: ADAPI):
self.logger.setLevel(logging.NOTSET)