tfriedel / python-lightify

Python module for Osram lightify. This is a work in progress.
Apache License 2.0
18 stars 9 forks source link

add support for external LogHandler #14

Closed rbdubz3 closed 5 years ago

rbdubz3 commented 5 years ago

This is a minor feature request to support an external LogHandler in order to output logging info for debugging/etc.. I am using this library with a home-grown plugin for Indigo Domotics ( https://github.com/rbdubz3/sylvania-lightify-indigo ).

See sample code snippets below - updated constructor plus new method to allow changing the log level:

class Lightify: """ main osram lightify class """ def init(self, host, new_device_types=None, loghandler=None): ....... ....... ....... 'max_temp': 6500 } } }} """ self.device_types = DEVICE_TYPES.copy() self.device_types.update(new_device_types or {})

    self.__logger = logging.getLogger(MODULE)
    self.__logger.setLevel(logging.INFO)
    if loghandler is not None:
        self.__logger.addHandler(loghandler)
    else:
        self.__logger.addHandler(logging.NullHandler())
    self.__logger.info("Initializing python %s, version=%s", MODULE, __version__)

    # a sequence number used to number commands sent to the gateway
    self.__seq = 0

....... ....... .......

def set_loglevel(self, debugLevel):
    self.__logger.setLevel(debugLevel)
    level_str = 'NOTSET'
    if debugLevel == logging.DEBUG:
        level_str = 'DEBUG'
    elif debugLevel == logging.INFO:
        level_str = 'INFO'
    elif debugLevel == logging.WARNING:
        level_str = 'WARNING'
    elif debugLevel == logging.ERROR:
        level_str = 'ERROR'
    elif debugLevel == logging.CRITICAL:
        level_str = 'CRITICAL'
    self.__logger.info("set_loglevel to '%s'", level_str)
OleksandrBerchenko commented 5 years ago

I'm not a repo owner, but I believe that should be a pull request not an opened issue :)

rbdubz3 commented 5 years ago

yeah - apologies if my git-etiquette is bad.. I actually tried to create a branch for this purpose but didn't have permissions. I guess I should fork it and submit a PR - does that sound right?

OleksandrBerchenko commented 5 years ago

Yes, you have to fork the repo, make the changes and create a PR back to this repo.

Thanks!

rbdubz3 commented 5 years ago

will submit as a PR