mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 12:37:45 +01:00
Only show timestamp for dashboard access logs (#2540)
This commit is contained in:
parent
f0089b7940
commit
70b62f272e
@ -758,7 +758,12 @@ def run_esphome(argv):
|
||||
args = parse_args(argv)
|
||||
CORE.dashboard = args.dashboard
|
||||
|
||||
setup_log(args.verbose, args.quiet)
|
||||
setup_log(
|
||||
args.verbose,
|
||||
args.quiet,
|
||||
# Show timestamp for dashboard access logs
|
||||
args.command == "dashboard",
|
||||
)
|
||||
if args.deprecated_argv_suggestion is not None and args.command != "vscode":
|
||||
_LOGGER.warning(
|
||||
"Calling ESPHome with the configuration before the command is deprecated "
|
||||
|
@ -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)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user