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:
+2
-2
@@ -178,11 +178,11 @@ class HeaterTask(ATask):
|
||||
try:
|
||||
self.device.process()
|
||||
except Exception as e:
|
||||
print(f"HeaterTask: comm error, marking disconnected: {e}")
|
||||
self.log.error(f"comm error, marking disconnected: {e}")
|
||||
self.disconnect()
|
||||
await asyncio.sleep(self.interval)
|
||||
except Exception as e:
|
||||
print(f"HeaterTask: unexpected error, recovering: {e}")
|
||||
self.log.error(f"unexpected error, recovering: {e}")
|
||||
try:
|
||||
self.disconnect()
|
||||
except Exception:
|
||||
|
||||
+1
-1
@@ -143,4 +143,4 @@ class ServerLogTask(ATask):
|
||||
for name in (filename, self._latest_filename()):
|
||||
with open(os.path.join(self.path, name), 'w') as f:
|
||||
json.dump(log_data, f, indent='\t')
|
||||
print('Server log: wrote {} samples to {}'.format(len(self._samples), filename))
|
||||
self.log.info('Wrote {} samples to {}'.format(len(self._samples), filename))
|
||||
|
||||
+2
-2
@@ -88,11 +88,11 @@ class StirrerTask(ATask):
|
||||
try:
|
||||
self.device.process()
|
||||
except Exception as e:
|
||||
print(f"StirrerTask: comm error, marking disconnected: {e}")
|
||||
self.log.error(f"comm error, marking disconnected: {e}")
|
||||
self.disconnect()
|
||||
await asyncio.sleep(self.interval)
|
||||
except Exception as e:
|
||||
print(f"StirrerTask: unexpected error, recovering: {e}")
|
||||
self.log.error(f"unexpected error, recovering: {e}")
|
||||
try:
|
||||
self.disconnect()
|
||||
except Exception:
|
||||
|
||||
+1
-1
@@ -634,7 +634,7 @@ class SudTask(ATask):
|
||||
await self.msg_handler.send(data)
|
||||
|
||||
async def on_process(self):
|
||||
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
|
||||
self.log.info("Started with interval {} s".format(self.interval))
|
||||
|
||||
self.sud.set_on_changed('step', self.on_step_changed)
|
||||
self.sud.set_on_changed('state', self.on_state_changed)
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ class TempSensorTask(ATask):
|
||||
try:
|
||||
self.sensor.temperature()
|
||||
except Exception as e:
|
||||
print(f"TempSensorTask: comm error priming sensor: {e}")
|
||||
self.log.error(f"comm error priming sensor: {e}")
|
||||
self.sensor.set_on_changed("temp", ChangedFloat(self.on_temp_changed, prec=1).set)
|
||||
|
||||
def on_temp_changed(self, value):
|
||||
@@ -44,5 +44,5 @@ class TempSensorTask(ATask):
|
||||
try:
|
||||
self.sensor.temperature()
|
||||
except Exception as e:
|
||||
print(f"TempSensorTask: comm error reading sensor: {e}")
|
||||
self.log.error(f"comm error reading sensor: {e}")
|
||||
await asyncio.sleep(self.interval)
|
||||
|
||||
Reference in New Issue
Block a user