WTH isn't it easier to change an integration's log level

When you are having an issue with an integration, one of the more useful steps is to change it’s log level to debug. Users are often asked to do this and share the logs in issues but doing this may avoid the need to make an issue in the first place if the debug log shows what’s wrong.

This can be done quickly and easily without a restart but it’s rather hidden.

  1. You have to know about the logger integration
  2. You have to find the info on the set level service and recognize that you can simply call services from developer tools
  3. You have to figure out which loggers to set to debug

#3 in particular is very tricky. Devs know that the logger you probably want to set to debug is homeassistant.components.<integration name>. But it doesn’t really say that anywhere and sometimes there are other loggers that can be useful to set to debug (like for a particular library the integration depends on with good logging).

It would be useful if integrations listed the loggers they used or an example service call in the doc. Or if there was a UI way to turn on and off debug logging on all the loggers of an integration without users needing to make these service calls.

It would be lovely if through the frontend that you could click on an integration and then turn on debug logs for the integration as well as its dependent library. The number of time I have had to explain how to do this for the integrations I’ve written…

3 Likes

There is an open/ongoing architecture discussion for this: Making it easier to enable debug logging · Discussion #715 · home-assistant/architecture · GitHub

1 Like

If there was a configuration page for each integration, similar to the configuration page for each device, there would be room, to show current version, current logging level, options to change logging, whether it was loaded via the UI or YAML.

Maybe I’m doing something wrong but, at least on 2022.9.x, from Developer Tools->Services, logger.set_level isn’t a known service.

Trying to call the service in YAML mode doesn’t work either

image

Huh, you might have to add logger: to your configuration.yaml to load logger. I assumed it was part of default_config but I see now that it is not. I’ve always had it in there to set the default log level so I never realized that was required. I guess add another step to the list.

Thanks for that. So you are saying there is yet another reason I might need to restart HA? :wink:

So now I’m wondering if logger has been added to default_config some time since my current installation was installed or whether this is a bug?

I guess. You only have to do it exactly one time though. You can just leave logger: in there after that, it doesn’t do anything except cause the service to be loaded. It’s not really a source of repeated restarts.

Neither (probably). If logger was added to default_config and you have default_config: in your configuration.yaml then you would see the logger services. Default config is not based on when you first started up HA, it loads the list of integrations here on startup. If an update to HA adds or removes integrations from that list then that also changes for you after you apply the update.

It might be a bug. Although that list is pretty carefully curated so its much more likely a feature request. I may not know the reason but I highly doubt it was accidentally omitted or removed.

I’m just curious how you even came up with that restart count with logging if you never used logger: in your config before?

PR to follow by mdegat01 on adding logger to default_config:

The result will be that logger.set_level and logger.set_defaul_level will be available as a service to all configurations. So the logger docs will wind up becoming correct :wink:

Note/warning: In the current release of HA if you just add logger: without setting the default level to your config, it will set the default log level to debug.

1 Like

Oh right, was working on it and forgot to share that back here. Thanks (I’m mdegat01 on GitHub :blush: )

1 Like