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 return
if line.startswith("csv,"): if line.startswith("csv,"):
return return
if line:
print(line)
time.sleep(0.5 * (attempt + 1)) time.sleep(0.5 * (attempt + 1))
print("WARN: did not see 'OK csv logging on' — continuing anyway", file=sys.stderr) print("WARN: did not see 'OK csv logging on' — continuing anyway", file=sys.stderr)
@@ -78,12 +80,6 @@ def main() -> int:
default=True, default=True,
help="Send 'log on' to the dryer after connect (default: on)", 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() args = parser.parse_args()
port = args.port port = args.port
@@ -131,32 +127,24 @@ def main() -> int:
line = raw.decode("utf-8", errors="replace").strip() line = raw.decode("utf-8", errors="replace").strip()
if not line.startswith("csv_hdr,") and not line.startswith("csv,"): if not line.startswith("csv_hdr,") and not line.startswith("csv,"):
if args.verbose and line: if line:
print(line, file=sys.stderr) print(line)
continue continue
if line.startswith("csv_hdr,"): if line.startswith("csv_hdr,"):
device_header = line[len("csv_hdr,") :] device_header = line[len("csv_hdr,") :]
row = "wall_time," + device_header fh.write("wall_time," + device_header + "\n")
fh.write(row + "\n")
header_written = True header_written = True
fh.flush() fh.flush()
if args.verbose:
print(row)
continue continue
if not header_written: if not header_written:
fh.write(FALLBACK_HEADER + "\n") fh.write(FALLBACK_HEADER + "\n")
header_written = True header_written = True
if args.verbose:
print(FALLBACK_HEADER)
wall_time = datetime.now(timezone.utc).isoformat(timespec="seconds") wall_time = datetime.now(timezone.utc).isoformat(timespec="seconds")
row = wall_time + "," + line[len("csv,") :] fh.write(wall_time + "," + line[len("csv,") :] + "\n")
fh.write(row + "\n")
fh.flush() fh.flush()
if args.verbose:
print(row)
if __name__ == "__main__": if __name__ == "__main__":