log: route task/component status output through logging, not print()

AttributeChange (the common base of every ATask and component ABC) now
sets self.log = logging.getLogger(type(self).__name__), so components
no longer need to hand-type their own name into each message. Wired
logging.basicConfig() in server/brewpi.py with a bare "%(name)s:
%(message)s" formatter - Tee (see prior commit) still supplies the
"<date>T<time>:" prefix, so lines read "<date>T<time>:<component>:
<message>" without double-stamping, and third-party loggers
(websockets, asyncio) now get the same formatting for free.

Converted the print() call sites that were standing in for this in
tasks/ and components/ (leaving __main__ demo blocks and explicit
debug-dump helpers alone).
This commit is contained in:
2026-07-10 22:00:04 +02:00
parent 6c746c8964
commit a1864a5257
12 changed files with 64 additions and 45 deletions
+6 -4
View File
@@ -1,3 +1,4 @@
import logging
import time
import serial
import enum
@@ -68,6 +69,7 @@ class StatusError(enum.IntFlag):
class Pololu1376:
def __init__(self, serial_port):
self.log = logging.getLogger(type(self).__name__)
# Deferred-open pyserial idiom: serial_port is constructed with no
# port set (see components/actor/stirrerpololu1376.py), so it isn't
# actually opened until connect() is called - a missing/unplugged
@@ -88,7 +90,7 @@ class Pololu1376:
self.ser.close()
self.ser.open()
except serial.SerialException as e:
print(f"Pololu1376: connect failed: {e}")
self.log.error(f"connect failed: {e}")
return False
# set_output_flow_control() requires the port to already be open -
# can only happen here, after open() above, not at construction time.
@@ -96,10 +98,10 @@ class Pololu1376:
try:
self.stop()
self.firmware_version = self.get_firmware_version()
print("Pololu1376 F/W-Version:", self.firmware_version)
self.log.info("F/W-Version: {}".format(self.firmware_version))
return True
except Exception as e:
print(f"Pololu1376: connect failed: {e}")
self.log.error(f"connect failed: {e}")
self.ser.close()
self.firmware_version = None
return False
@@ -142,7 +144,7 @@ class Pololu1376:
rsp = self.cmd("GO")
errors = self.get_status_errors()
if errors:
print(f"Pololu1376: ERROR - still in fail-safe after GO, active errors: {errors!r}")
self.log.error(f"still in fail-safe after GO, active errors: {errors!r}")
return rsp
def stop(self):