Replies: 4 comments 2 replies
-
Not fully clear to me what this means.
What is the difference between the log of an config entry and an integration? Also: "integration + device" does that mean those are always mixed up in the log you are looking at? e.g., If I'm viewing the log of an ESPHome device they will mix up logs from the device and HA Python? |
Beta Was this translation helpful? Give feedback.
-
Haven't tried this but could we use something like https://github.com/deansg/py-logging-context (which uses ContextVar to work in async contexts) to attach the config entry id or even the device id to log entries automatically? When I look at HomeKit device logs they frequently include multiple unrelated devices, so it would be amazing to filter by config entry id. Maybe we can even use the same to also be able to capture logs for a single config flow using its unique id, and offer a log download for that flow if it fails. If I understand it correctly and we can actually automatically attach ids to log entries using ContextVars then we might not even need to rely exclusively on the manifest loggers metadata, as it would apply to any logger used within a particular contextvar context? Another case where this might be useful might be matter and i assume zwave? Eg If we can get matter to emit sufficiently structured json logs we could potentially correlate and filter logs by their node id in the add on, and link to a device id in HA (unfortunately there aren't per device config entries there, so it would be by device and not config entry). |
Beta Was this translation helpful? Give feedback.
-
For real-time logs, there are cases where we would want to see the HA logs in the same place as the remote device log since there are many cases where an event on the HA side proceeds and an event on the device side and a single combined view is key to understanding the chain of events. The difficulty is that we don't always know which loggers to enable on the HA side. For example, suppose someone is having a problem connecting to the Bluetooth device. In that case, we need them to turn on the ESPHome loggers, the Bluetooth loggers, and the loggers for the device itself, and hopefully nothing else that generates too much noise. Knowing which loggers to turn on is a skill the user likely lacks, as it requires some basic understanding of the design and which code is run end to end. |
Beta Was this translation helpful? Give feedback.
-
One thought is to have everything for remote devices go to a specific logger for the integration through the standard Python logging API, maybe a sub namespace of the integration. Then we can attach to that logger set and stream it to the UI. We could have specific predefined sets of loggers to turn on that a user could paste in or click through something like One potential implementation would be to give them a list of integrations to check off, and it starts debug logging for those integration, the websocket gets connected and sets up a new log handler to go to the websocket with a filter for just those integrations to stream in real time. At the end of the session they can download the streamed log. Few items to work out: Do we also save the debug session log to a file? |
Beta Was this translation helpful? Give feedback.
-
Context
When things go wrong, it's hard to sometimes see what is going on. The best bet is to look if an exception is logged. If that's not the case, the second best option is to look at the debug logs of an integration and then reproduce the broken behavior. To get to the logs, however, is a pain. It requires knowledge of the integration to inspect, the
logger
integration and how to access it all.We've worked on this in the past, and each integration already specifies loggers in their manifest that are used for logging data.
In some cases, the integration could also be able to provide their own logs that are interesting for the user. For example, an ESPHome device could stream the logs of what is happening on the actual device.
Being able to see real-time what is happening on the ESPHome device and the ESPHome integration would be a powerful tool to self-help, or be helped to track down issues.
Proposal
We add a new websocket API that allows the frontend to subscribe to logs from a specific config entry + device combo
An integration will add a logger platform with a new method. This is called when the user requests logs for a device and is provided with a callback method to sent logs to the frontend. The method has to return a function when the logging has to be stopped.
It is up to an integration to subscribe to device specific logs and pass them to
log_messages
. Log messages is a callback function. The returned unsubscribe function is also a callback function.Consequences
It will be a lot easier to help people track down issues. We can ask people with problems to download the logs and attach them to issues (the debug logs might be too revealling, but device logs can be more suitable).
Beta Was this translation helpful? Give feedback.
All reactions