diff --git a/iottly_sdk/iottly.py b/iottly_sdk/iottly.py index ae16fe1..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 @@ -349,6 +360,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 + logger.error("Permission denied, launch with proper permission") + return + except OSError as e: if e.errno == errno.ECONNREFUSED: s.close()