From 816a86f955a53c317342ce969a8812b48ab01fa6 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 23 Sep 2022 10:01:13 +0200 Subject: [PATCH] ucloud: Update logging messages and levels. --- arduino_iot_cloud/ucloud.py | 16 ++++++++-------- arduino_iot_cloud/umqtt.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arduino_iot_cloud/ucloud.py b/arduino_iot_cloud/ucloud.py index ab2c113..d49ffa6 100644 --- a/arduino_iot_cloud/ucloud.py +++ b/arduino_iot_cloud/ucloud.py @@ -106,10 +106,10 @@ def value(self, value): ) self._updated = True self.timestamp = timestamp() - logging.debug( - f"record: {self.name} %s: {value} ts: {self.timestamp}" - % ("initialized" if self.value is None else "updated") - ) + if (self.value is None): + logging.info(f"Init: {self.name} value: {value} ts: {self.timestamp}") + else: + logging.debug(f"Update: {self.name} value: {value} ts: {self.timestamp}") self._value = value def __is_subrecord(self, attr): @@ -218,7 +218,7 @@ def update_systime(self): def create_task(self, name, coro, *args, **kwargs): self.tasks[name] = asyncio.create_task(coro(*args)) - logging.debug(f"task: {name} created.") + logging.info(f"task: {name} created.") def create_topic(self, topic, inout): return bytes(f"/a/t/{self.thing_id}/{topic}/{inout}", "utf-8") @@ -244,9 +244,9 @@ def senml_generic_callback(self, record, **kwargs): # This callback catches all unknown/umatched sub/records that were not part of the pack. rname, sname = record.name.split(":") if ":" in record.name else [record.name, None] if rname in self.records: - logging.debug(f"Ignoring cloud initialization for record: {record.name}") + logging.info(f"Ignoring cloud initialization for record: {record.name}") else: - logging.info(f"Unkown record found: {record.name} value: {record.value}") + logging.warning(f"Unkown record found: {record.name} value: {record.value}") def mqtt_callback(self, topic, message): logging.debug(f"mqtt topic: {topic[-8:]}... message: {message[:8]}...") @@ -285,7 +285,7 @@ async def mqtt_task(self, interval=0.100): record.add_to_pack(self.senmlpack, push=True) if len(self.senmlpack._data): logging.debug("Pushing records to Arduino IoT cloud:") - for record in self.senmlpack: + for record in self.senmlpack._data: logging.debug(f" ==> record: {record.name} value: {str(record.value)[:48]}...") self.mqtt.publish(self.topic_out, self.senmlpack.to_cbor(), qos=True) self.last_ping = timestamp() diff --git a/arduino_iot_cloud/umqtt.py b/arduino_iot_cloud/umqtt.py index 4ed78cb..52d8690 100644 --- a/arduino_iot_cloud/umqtt.py +++ b/arduino_iot_cloud/umqtt.py @@ -151,7 +151,7 @@ def connect(self, retry=10, interval=1.0, clean_session=True): return True except Exception as e: self.sock.close() - logging.info(f"Connection failed {e}, retrying after {interval}s") + logging.warning(f"Connection failed {e}, retrying after {interval}s") time.sleep(interval) return False @@ -198,7 +198,7 @@ def publish(self, topic, msg, retain=False, qos=0): assert 0 def subscribe(self, topic, qos=0): - logging.info(f"Subscribing to topic: {topic}.") + logging.info(f"Subscribe: {topic}.") assert self.cb is not None, "Subscribe callback is not set" pkt = bytearray(b"\x82\0\0\0") self.pid += 1