1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 13:52:20 +01:00

Only show timestamp for dashboard access logs (#2540)

This commit is contained in:
Otto Winter
2021-10-17 21:01:51 +02:00
committed by GitHub
parent 12fce7a08d
commit 5425e45851
2 changed files with 16 additions and 5 deletions

View File

@@ -49,8 +49,10 @@ def color(col: str, msg: str, reset: bool = True) -> bool:
class ESPHomeLogFormatter(logging.Formatter):
def __init__(self):
super().__init__(fmt="%(asctime)s %(levelname)s %(message)s", style="%")
def __init__(self, *, include_timestamp: bool):
fmt = "%(asctime)s " if include_timestamp else ""
fmt += "%(levelname)s %(message)s"
super().__init__(fmt=fmt, style="%")
def format(self, record):
formatted = super().format(record)
@@ -64,7 +66,9 @@ class ESPHomeLogFormatter(logging.Formatter):
return f"{prefix}{formatted}{Style.RESET_ALL}"
def setup_log(debug=False, quiet=False):
def setup_log(
debug: bool = False, quiet: bool = False, include_timestamp: bool = False
) -> None:
import colorama
if debug:
@@ -79,4 +83,6 @@ def setup_log(debug=False, quiet=False):
logging.getLogger("urllib3").setLevel(logging.WARNING)
colorama.init()
logging.getLogger().handlers[0].setFormatter(ESPHomeLogFormatter())
logging.getLogger().handlers[0].setFormatter(
ESPHomeLogFormatter(include_timestamp=include_timestamp)
)