How to enable debug logging for custom component AND its libraries from UI?

I am trying to make a custom component more friendly for use by supporting the UI enable debug logging feature, vs. needing to enable debug logging for the custom component and its main pypi library.

When using enable debug logging from the UI only the custom component logging is set to debug.
I can modify the init code to propagate the active log level to the library. But, when a user disables logging from the UI, HA disables logging for the custom component only.

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Vantage integration from a config entry."""

    # Assign the HA configured log level of this module to the aiovantage module
    this_logger: logging.Logger = logging.getLogger(__name__)
    aiovantage_logger: logging.Logger = logging.getLogger("aiovantage")
    log_level: int = this_logger.getEffectiveLevel()
    aiovantage_logger.setLevel(log_level)
    this_logger.info(f"Logging at level: {log_level}")

I found documentation and an issue for adding a loggers entry to the manifest, but the documentation is not clear, and the issue seems a workaround, that did not work.

How can I by UI command enable debug logging for the custom component itself, and a configurable list of other components?

So it looks like the UI not showing the debug option was just a timing issue.
If I add both the custom component and the library to loggers then both are debug enabled, and the UI works, just need to be patient after rebooting.
The documentation for loggers can do with some expansion.

1 Like