From 007f05595b1792bb6c54b102436946d2bfbc8370 Mon Sep 17 00:00:00 2001 From: SaiT2 Date: Fri, 2 Oct 2020 15:45:12 +0200 Subject: [PATCH 1/2] Added message log to report lack of permission when using the sdk --- iottly_sdk/iottly.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iottly_sdk/iottly.py b/iottly_sdk/iottly.py index ae16fe1..43eae89 100644 --- a/iottly_sdk/iottly.py +++ b/iottly_sdk/iottly.py @@ -349,6 +349,13 @@ def _connect_to_agent(self): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: s.connect(self._socket_path) + + except PermissionError as e: + s.close() + s = None + logging.info("Permission denied, launch with proper permission") + return + except OSError as e: if e.errno == errno.ECONNREFUSED: s.close() From ce84ca08b7141029f4e1014ed6549f7748e906c4 Mon Sep 17 00:00:00 2001 From: SaiT2 Date: Fri, 2 Oct 2020 16:16:59 +0200 Subject: [PATCH 2/2] Added logger --- iottly_sdk/iottly.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/iottly_sdk/iottly.py b/iottly_sdk/iottly.py index 43eae89..c775a73 100644 --- a/iottly_sdk/iottly.py +++ b/iottly_sdk/iottly.py @@ -27,6 +27,7 @@ from Queue import Queue, Full import json +import logging # Import the SDK version number from .version import __version__ @@ -38,6 +39,16 @@ Msg = namedtuple('Msg', ['payload', 'type', 'channel']) +logger = logging.getLogger('iottly-sdk') +logger.setLevel(logging.ERROR) +sh = logging.StreamHandler() +sh.setLevel(logging.ERROR) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +sh.setFormatter(formatter) +logger.addHandler(sh) + + + class IottlySDK: """Class handling interactions with the iottly-agent @@ -353,7 +364,7 @@ def _connect_to_agent(self): except PermissionError as e: s.close() s = None - logging.info("Permission denied, launch with proper permission") + logger.error("Permission denied, launch with proper permission") return except OSError as e: