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:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
|
||||
|
||||
class Value:
|
||||
@@ -53,6 +54,12 @@ class ChangedInteger(object):
|
||||
class AttributeChange(object):
|
||||
def __init__(self):
|
||||
self.callbacks = {}
|
||||
# Common ancestor of every task (tasks/task.py's ATask) and component
|
||||
# (Connectable/APid/APlant/ATemperatureSensor) - giving it a logger
|
||||
# here makes self.log available everywhere via one change, named
|
||||
# after the concrete subclass so log lines self-identify their
|
||||
# component without each call site typing it out.
|
||||
self.log = logging.getLogger(type(self).__name__)
|
||||
|
||||
def set_on_changed(self, key, on_changed):
|
||||
if key not in self.callbacks:
|
||||
|
||||
Reference in New Issue
Block a user