refine logging

This commit is contained in:
2026-07-05 10:36:05 +02:00
parent 81f9bb8870
commit 161cbab8a7

View File

@@ -48,6 +48,8 @@ def enable_dryer_logging(ser, retries: int = 3) -> None:
return
if line.startswith("csv,"):
return
if line:
print(line)
time.sleep(0.5 * (attempt + 1))
print("WARN: did not see 'OK csv logging on' — continuing anyway", file=sys.stderr)
@@ -78,12 +80,6 @@ def main() -> int:
default=True,
help="Send 'log on' to the dryer after connect (default: on)",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="Echo captured CSV rows to stdout; other serial lines to stderr",
)
args = parser.parse_args()
port = args.port
@@ -131,32 +127,24 @@ def main() -> int:
line = raw.decode("utf-8", errors="replace").strip()
if not line.startswith("csv_hdr,") and not line.startswith("csv,"):
if args.verbose and line:
print(line, file=sys.stderr)
if line:
print(line)
continue
if line.startswith("csv_hdr,"):
device_header = line[len("csv_hdr,") :]
row = "wall_time," + device_header
fh.write(row + "\n")
fh.write("wall_time," + device_header + "\n")
header_written = True
fh.flush()
if args.verbose:
print(row)
continue
if not header_written:
fh.write(FALLBACK_HEADER + "\n")
header_written = True
if args.verbose:
print(FALLBACK_HEADER)
wall_time = datetime.now(timezone.utc).isoformat(timespec="seconds")
row = wall_time + "," + line[len("csv,") :]
fh.write(row + "\n")
fh.write(wall_time + "," + line[len("csv,") :] + "\n")
fh.flush()
if args.verbose:
print(row)
if __name__ == "__main__":