button work
This commit is contained in:
19
console.py
19
console.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user