AppDaemon Debug Mode

Ok I did this

in init do the following
    self.LOGLEVEL="DEBUG"    

Then I ovrerode self.log so it uses the same parameters as the normal one, But if self.LOGLEVEL is set, then if the level you pass through to log is < LOGLEVEL, it will print out the message. Otherwise, it skips it like the python logger does.

  def log(self,message,level="INFO"):
    levels = {
              "CRITICAL": 50,
              "ERROR": 40,
              "WARNING": 30,
              "INFO": 20,
              "DEBUG": 10,
              "NOTSET": 0
            }
    if hasattr(self, "LOGLEVEL"):
      if levels[level]>=levels[self.LOGLEVEL]:
        super().log("{} - message={}".format(level,message))
    else:
      super().log("{}".format(message),level)

Because I’m using the python’s logger, it still gets their status at the beginning of the line, and then my status shows up further down the line, but it serves my purpose.

2 Likes