diff --git a/lightify/__init__.py b/lightify/__init__.py index e0cdca6..1ba3864 100644 --- a/lightify/__init__.py +++ b/lightify/__init__.py @@ -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 @@ -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 @@ -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