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

[core] Add millisecond precision to logging timestamps (#10677)

This commit is contained in:
J. Nick Koston
2025-09-11 14:25:55 -05:00
committed by GitHub
parent 625f108183
commit 5fd64c5c89
2 changed files with 8 additions and 4 deletions

View File

@@ -226,7 +226,9 @@ def run_miniterm(config: ConfigType, port: str, args) -> int:
.replace(b"\n", b"") .replace(b"\n", b"")
.decode("utf8", "backslashreplace") .decode("utf8", "backslashreplace")
) )
time_str = datetime.now().time().strftime("[%H:%M:%S]") time_ = datetime.now()
nanoseconds = time_.microsecond // 1000
time_str = f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}.{nanoseconds:03}]"
safe_print(parser.parse_line(line, time_str)) safe_print(parser.parse_line(line, time_str))
backtrace_state = platformio_api.process_stacktrace( backtrace_state = platformio_api.process_stacktrace(

View File

@@ -62,9 +62,11 @@ async def async_run_logs(config: dict[str, Any], addresses: list[str]) -> None:
time_ = datetime.now() time_ = datetime.now()
message: bytes = msg.message message: bytes = msg.message
text = message.decode("utf8", "backslashreplace") text = message.decode("utf8", "backslashreplace")
for parsed_msg in parse_log_message( nanoseconds = time_.microsecond // 1000
text, f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]" timestamp = (
): f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}.{nanoseconds:03}]"
)
for parsed_msg in parse_log_message(text, timestamp):
print(parsed_msg.replace("\033", "\\033") if dashboard else parsed_msg) print(parsed_msg.replace("\033", "\\033") if dashboard else parsed_msg)
stop = await async_run(cli, on_log, name=name) stop = await async_run(cli, on_log, name=name)