Skip to content

Commit

Permalink
Merge pull request #16 from rbdubz3/master
Browse files Browse the repository at this point in the history
optional logging - level and custom handler
  • Loading branch information
tfriedel authored Feb 10, 2019
2 parents 953e77d + 7597a24 commit 08c5876
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lightify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def __str__(self):
class Lightify:
""" main osram lightify class
"""
def __init__(self, host, new_device_types=None):
def __init__(self, host, new_device_types=None, log_level=logging.INFO, loghandler=None):
"""
:param host: lightify gateway host
:param new_device_types: dict of additional device types to merge with
Expand All @@ -918,13 +918,19 @@ def __init__(self, host, new_device_types=None):
}
}
}}
:param log_level: logging.loglevel Enum
:param loghandler: logging.Handler object
"""
self.__device_types = DEVICE_TYPES.copy()
self.__device_types.update(new_device_types or {})

self.__logger = logging.getLogger(MODULE)
self.__logger.addHandler(logging.NullHandler())
self.__logger.info('Logging %s', MODULE)
self.__logger.setLevel(log_level)
if loghandler:
self.__logger.addHandler(loghandler)
else:
self.__logger.addHandler(logging.NullHandler())
self.__logger.info('Initializing %s, version=%s', MODULE, __version__)

# a sequence number used to number commands sent to the gateway
self.__seq = 0
Expand Down Expand Up @@ -968,6 +974,14 @@ def _next_seq(self):
self.__seq = (self.__seq + 1) % 256
return self.__seq

def set_loglevel(self, log_level):
""" set the log level
:param log_level: logging.loglevel Enum
"""
self.__logger.setLevel(log_level)
self.__logger.info("set log level to '%s'", logging.getLevelName(log_level))

def set_lights_updated(self):
""" update lights updated timestamp
Expand Down

0 comments on commit 08c5876

Please sign in to comment.