From db63eb6d792118f88cfeb832563de7a0afaa06b8 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Wed, 25 Mar 2026 15:05:01 +0200 Subject: [PATCH] [P] Improve logging logic in agent --- agent/src/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/src/main.py b/agent/src/main.py index eff8da8..1b43cc5 100644 --- a/agent/src/main.py +++ b/agent/src/main.py @@ -16,6 +16,8 @@ def connect_mqtt(broker, port): print("Failed to connect {broker}:{port}, return code %d\n", rc) exit(rc) # Stop execution + logging.info(f"Acting as USER_ID = {config.USER_ID}") + client = mqtt_client.Client() client.on_connect = on_connect client.connect(broker, port) @@ -29,13 +31,14 @@ def publish(client, topic, datasource): data = datasource.read() msg = AggregatedDataSchema().dumps(data) result = client.publish(topic, msg) - logging.info(f"Published to {topic}: {msg[:50]}...") + logging.debug(f"Published to {topic}: {msg[:50]}...") status = result[0] if status != 0: - print(f"Failed to send message to topic {topic}") + logging.error(f"Failed to send message to topic {topic}") def run(): + logging.basicConfig(level = logging.INFO) # Prepare mqtt client client = connect_mqtt(config.MQTT_BROKER_HOST, config.MQTT_BROKER_PORT) # Prepare datasource -- 2.49.1