AppDaemon logging

Hi amic,

Sorry to bother you with what is more of a python question than a AppDaemon question but im trying to extend the logging so I can have individual files per app and was wondering if you could give some advice on it.

Here is what I have in def initialize

    def initialize(self):
        logger = logging.getLogger(self.name)
        logger.setLevel(logging.DEBUG)
        logfile = "/var/log/appdaemon/apps/AutoLights.{}.log".format(self.name)
        filelogger = logging.FileHandler(logfile)
        filelogger.setLevel(logging.DEBUG)
        logger.addHandler(filelogger)

The im just using

logger.info('whatever)

currently im passing it in as follows, which is working ok.

logger=kwargs['logger`']

What do you think would be the best way of passing this to the other functions in the app. Making it global is no good as its shared by all the other AppDaemon apps?? Should I pass it around as an argument? is there a better (more established way of doing this?)

Cheers
Zak

Hi there -

How about using an object variable, e.g. self.logger ? That will be visible from all the functions in your app, but not outside the app.

fantastic, works perfectly.

Do you think it might be possible to extend the appdaemon logger to allow logging to individual files?

Cheers
Zak

it is easy to create your own logger.

just make a general app named own_logger
with a def called logger

and then use

   self.logging = self.get_app("own_logger") # in the initialize

    logging.logger("log info","appname") #anywhere in your app

and off course you could also import any other logging lib and use that everywhere.

Cheers guys.