Setting AppDeamon log level in appdeamon.yaml?

Hello,

I have created an user-defined log for my appdeamon app.
Is there a way to set the level threshold to define the log messages we want to have logged in the file?

Something like this:

# Log files
logs:
  main_log:
    filename: /config/logs/appdaemon.log
    
  access_log:
    filename: /config/logs/access.log

  error_log:
    filename: /config/logs/error.log
  
  my_user_defined_log:
    name: MyLog
    filename: /config/logs/my.log
    level: WARNING # only messages with level WARNING or higher are logged to my.log
    log_generations: 3
    log_size: 100000

Thank you for your help!

Luis

I don’t think you can based on the docs because that’s probably not the best way to do that.

Instead

Either set the log level when you call self.log using the variable level=*

Example

self.log("Log Test: Parameter is %s", some_variable, level = "ERROR")
# or better
self.log(f"Log Test: Parameter is {some_variable}", level = "ERROR")

Or you can set the log level at the app configuration using the keywords log_level: *

Example

persons:
  module: persons
  class: Castle
  priority: 5
  log: home
  log_level: INFO
  global_dependencies: WorldConst

you can also change the logging level of the app while it is running using self.set_log_level

Thank you for your suggestion, @Vesha !

Just added a log_level parameter, and added a function like that:

def set_log_level_from_args(self):

        """
        Defines the log level based on app parameter 'log_level'.
        """
        log_level: str = self.args.get('log_level', None)

        if log_level:
            self.set_log_level(log_level)
            self.log(f'Log level: {log_level}')

Then I call this in initialize. And it works!

Actually setting log_level in the app parameters will automatically set the log level for the app. No need for that function.

1 Like