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:
@@ -46,7 +46,7 @@ class StirrerPololu1376(AStirrer):
|
||||
if not self.connected:
|
||||
return
|
||||
try:
|
||||
print("activate {}".format(enable))
|
||||
self.log.debug("activate {}".format(enable))
|
||||
if enable:
|
||||
self.drv.go()
|
||||
else:
|
||||
@@ -58,7 +58,7 @@ class StirrerPololu1376(AStirrer):
|
||||
# loop (with self.device.open(): activate(True)/(False)) and
|
||||
# from a client's Connect/Disconnect command, neither of which
|
||||
# expect activate() itself to ever raise.
|
||||
print(f"StirrerPololu1376: comm error in activate({enable}): {e}")
|
||||
self.log.error(f"comm error in activate({enable}): {e}")
|
||||
self.disconnect()
|
||||
|
||||
def _on_set_speed(self, speed):
|
||||
@@ -66,9 +66,9 @@ class StirrerPololu1376(AStirrer):
|
||||
return
|
||||
try:
|
||||
self.drv.motor_forward(speed)
|
||||
print("Set speed to {} %".format(speed))
|
||||
self.log.debug("Set speed to {} %".format(speed))
|
||||
except Exception as e:
|
||||
print(f"StirrerPololu1376: comm error in _on_set_speed: {e}")
|
||||
self.log.error(f"comm error in _on_set_speed: {e}")
|
||||
self.disconnect()
|
||||
|
||||
def _on_process(self):
|
||||
@@ -77,12 +77,12 @@ class StirrerPololu1376(AStirrer):
|
||||
try:
|
||||
errors = self.drv.get_status_errors()
|
||||
if errors:
|
||||
print(f"StirrerPololu1376: motor controller reports errors: {errors!r}")
|
||||
self.log.warning(f"motor controller reports errors: {errors!r}")
|
||||
if StatusError.SAFE_START_VIOLATION in errors:
|
||||
print("Recover after safe start violation!")
|
||||
self.log.warning("Recover after safe start violation!")
|
||||
self.drv.go()
|
||||
except Exception as e:
|
||||
print(f"StirrerPololu1376: comm error in _on_process: {e}")
|
||||
self.log.error(f"comm error in _on_process: {e}")
|
||||
self.disconnect()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user