diff mbox series

[4/5] examples/client: improve websocket message handling

Message ID 20230116195059.25744-5-daniel@braunwarth.dev
State Accepted
Delegated to: Stefano Babic
Headers show
Series examples/client: Various improvements | expand

Commit Message

Daniel Braunwarth Jan. 16, 2023, 7:50 p.m. UTC
This patch maps the logging level used by SWUpdate to the logging levels
used by Python and logs them with the actual level.

Signed-off-by: Daniel Braunwarth <daniel@braunwarth.dev>
---
 examples/client/swupdate_client.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Stefano Babic Jan. 22, 2023, 5:53 p.m. UTC | #1
> This patch maps the logging level used by SWUpdate to the logging levels
> used by Python and logs them with the actual level.
> Signed-off-by: Daniel Braunwarth <daniel@braunwarth.dev>
Applied to swupdate, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/examples/client/swupdate_client.py b/examples/client/swupdate_client.py
index 78e92f1..751a268 100755
--- a/examples/client/swupdate_client.py
+++ b/examples/client/swupdate_client.py
@@ -16,6 +16,14 @@  import requests
 import websockets
 
 
+LOGGING_MAPPING = {
+    "3": logging.ERROR,
+    "4": logging.WARNING,
+    "6": logging.INFO,
+    "7": logging.DEBUG,
+}
+
+
 class SWUpdater:
     """Python helper class for SWUpdate"""
 
@@ -58,7 +66,10 @@  class SWUpdater:
                     if data["type"] != "message":
                         continue
 
-                    self._logger.info(data["text"])
+                    self._logger.log(
+                        LOGGING_MAPPING[data["level"]],
+                        data["text"])
+
                     if "SWUPDATE successful" in data["text"]:
                         return True
                     if "Installation failed" in data["text"]: