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
+8 -6
View File
@@ -1,5 +1,6 @@
#!/usr/bin/python3
import logging
import time
import serial
import sys
@@ -11,6 +12,7 @@ class HendiException(Exception):
class HendiCtrl:
def __init__(self, port, speed, debug=False):
self.log = logging.getLogger(type(self).__name__)
self.debug = debug
self.prompt = b':'
self.sw_id = None
@@ -48,7 +50,7 @@ class HendiCtrl:
try:
self.ser.open()
except serial.SerialException as e:
print(f"HendiCtrl: connect failed: {e}")
self.log.error(f"connect failed: {e}")
return False
# The port itself is what "connected" means - a failed version query
# (e.g. the device sitting in its ungraceful-disconnect lockout, see
@@ -57,9 +59,9 @@ class HendiCtrl:
try:
self.sw_id = self.getSoftwareIdentifier()
self.sw_ver = self.getSoftwareVersion()
print(f"{self.sw_id}, F/W-Version: {self.sw_ver}")
self.log.info(f"{self.sw_id}, F/W-Version: {self.sw_ver}")
except HendiException:
print("HendiCtrl: Hendi not found")
self.log.warning("Hendi not found")
return True
@contextmanager
@@ -91,7 +93,7 @@ class HendiCtrl:
self.ser.rts = True
def firmware_update(self, filename):
print("Start firmware update")
self.log.info("Start firmware update")
self.enter_bootloader()
self.ser.readline()
@@ -122,7 +124,7 @@ class HendiCtrl:
self.ser.flushInput()
data = s.encode()
if self.debug:
print(f"HendiCtrl: -> {data!r}")
self.log.debug(f"-> {data!r}")
self.ser.write(data + b'\r')
def __read(self):
@@ -132,7 +134,7 @@ class HendiCtrl:
# Read answer line
answer_raw = self.ser.readline()
if self.debug:
print(f"HendiCtrl: <- echo={echo!r} answer={answer_raw!r}")
self.log.debug(f"<- echo={echo!r} answer={answer_raw!r}")
answer = answer_raw.decode('utf-8').replace('\r', '').replace('\n', '')
if ':' in answer:
result = answer.split(':')