Logger set_level

Hi there, found this in the docs and think it’s a nice feature.


Made some input_select
log_level:
  name: Log Level
  options:
    - critical
    - fatal
    - error
    - warning
    - warn
    - info
    - debug
    - notset
  initial: warn

and an automation

- alias: Log Level
  trigger:
    platform: state
    entity_id: input_select.log_level
  action:
    service: logger.set_level
    data_template:
      homeassistant.components: "{{ trigger.to_state.state }}"

Now i can switch the loglevel at runtime.

17 Likes

Do you mean you can set logger levels while HA is running?

Yes! This is what i mean.

1 Like

What a great idea! Thanks; I’m definitely adding this to my setup.

Thanks for posting this but I’m having trouble with it. If I have “logger:” in my main config file, in addition to the entries you posted above, I get full logs of everything no matter how tight I set the input selector. When I remove “logger:” I only get WARNING and ERROR messages, including this one:

2017-06-01 22:49:44 WARNING (MainThread) [homeassistant.core] Unable to find service logger/set_level

Any idea what I’m missing?

Hi @hoffsta, maybe the logger needs a default level?
This is what i have in my config:

logger:
  default: warn
  logs:
    homeassistant.components.updater: debug
    homeassistant.components.automation: info
    ...

OK, I setup logger as so:

logger:
  default: warn
  logs:
    homeassistant.components.mqtt: debug
    homeassistant.components.automation: debug

I can change the input selector but I don’t see any change to the logging. In the above configuration, with the selector set to ‘error’, I still see lots of debug entries in mqtt and automation components. If I set the slider to ‘debug’ I don’t see debug entries from other components.

What is the expected behavior? Maybe I don’t understand the purpose correctly.

The logger.set_level sets only the default level. The entries in ‘logs:’ stay in the level they are configured.
If you set only:

logger:
  default: warn

and you select from ‘warn’ to ‘debug’, there should be a massive difference in the log, or anything is wrong.
Do you have entries like:
2017-06-02 10:59:34 INFO (MainThread) [homeassistant.components.automation] Executing Log Level in the log when you select values above ‘info’?

@VDRainer Could you please check if this is still working for you in 0.91.4 (or whatever release you are running)? The reason I am asking: it does no longer work for me and it might be caused by homeassistant.loader logger severity ignored · Issue #21745 · home-assistant/core · GitHub

I’m on 0.92.0b3 and the automation works as expected.

Can you also change the log level this way?

grafik

It used to work for me, but no longer does and I have no idea how to troubleshoot that.

Have you tried it with the automation?
The service shows that it takes no parameters.
Auswahl_035

Just found out that it works when using set_default_level instead of set_level.

I’m getting the following error with this automation

> ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.log_level. Invalid data for call_service at pos 1: extra keys not allowed @ data['homeassistant.components']

- alias: Log Level
  initial_state: True
  trigger:
    platform: state
    entity_id: input_select.log_level
  action:
    service: logger.set_default_level
    data_template:
      homeassistant.components: "{{ trigger.to_state.state }}"

Have you tried logger.set_level ?
It’s a bit confusing with the service tool and the service call.
Don’t know if this is a bug.