Improve Logging Documentation with Overview#140
Conversation
✅ Deploy Preview for esphome-dev-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Adds a new high-level overview page for ESPHome's logging framework aimed at developers/advanced users, restructures the navigation to group logging docs under a new section, and augments the (renamed) best-practices page with guidance against logging component state changes.
Changes:
- Add
docs/architecture/logging/overview.mdcoveringESP_LOGmacro usage, log levels, and how to obtain logs via serial / network API / MQTT. - Update
docs/architecture/logging/best_practices.md(renamed location) with a new "Logging State Changes: Don't" section and minor wording tweaks. - Update
mkdocs.ymlnavigation to introduce aLoggingsubsection withOverviewandBest Practicespages.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| mkdocs.yml | Adds the new Logging subsection grouping the overview and best-practices pages. |
| docs/architecture/logging/overview.md | New overview document for ESPHome logging framework. |
| docs/architecture/logging/best_practices.md | Adds state-change logging guidance and minor wording/formatting cleanup. |
Comments suppressed due to low confidence (1)
docs/architecture/logging/best_practices.md:58
- "irregardless" is non-standard; use "regardless".
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| `void ESP_LOGD(const char * TAG, const char * msg, void **margs)` | ||
|
|
||
| `TAG` is usually defined in a component's header and/or at the top of the source code file as a |
|
|
||
| The `ESP_LOG` macro is available to perform all of the necessary log functions in a space- and processing-efficient manner. The macro has the following signature (using the `DEBUG` log channel): | ||
|
|
||
| `void ESP_LOGD(const char * TAG, const char * msg, void **margs)` |
| this->update_interval_, | ||
| this->samples_, | ||
| this->get_mode_str()); | ||
| } |
| can then connect to your computer using: | ||
|
|
||
| - A deducated USB to UART adapter, or | ||
| - An [RP2040 Debug Probe](https://www.raspberrypi.com/products/debug-probe/) or another RP2040 device such as a Raspberry Pi Pico loaded with [debug probe firmware](github.com/raspberrypi/debugprobe). This will work for any UART-capable ESPHome device, not just RP2040 devices. |
| - `VERBOSE` (`ESP_LOGV()`): Messages that don't normally need to be seen but may add value when troubleshooting or preparing/commissioning a new device/configuration. | ||
| - `VERY_VERBOSE` (`ESP_LOGVV()`): Detailed technical information, such as the content of data packets/messages being processed and/or processing state/status. | ||
|
|
||
| By default, `DEBUG` is the lowest severity level message type that are logged. To log less verbose messages, change the `logger` component's `level` to the desired log level, recompile, and reflash the firmware onto the device. |
| ## Obtaining Log Data | ||
|
|
||
| In general, you can use `esphome logs` to retrieve real-time logs from a running ESPHome device over serial or the network API: | ||
|
|
||
| ```bash | ||
| esphome logs path/to/configuration.yaml | ||
| ``` | ||
|
|
||
| If both network and serial connections for a single device are available, or if multiple devices are connected over serial, `esphome` will give you a choice of connection. You can automatically select the correct device using the `--device` flag: | ||
|
|
||
| ```bash | ||
| esphome logs --device 192.168.1.111 path/to/configuration.yaml | ||
| esphome logs --device ttyACM1 path/to/configuration.yaml | ||
| ``` | ||
|
|
||
| !!! important "Missing Logs over Network API" | ||
| Some problems may be difficult to troubleshoot when using the Network API, either due to the errors occurring well before the device network stack is initialized, or if the network stack itself is causing an issue. If this is the case, you may need to use hardware serial to obtain logs. | ||
|
|
||
|
|
||
| To retrieve logs over serial, you can either configure your hardware's USB CDC if it has such hardware, or configure your device to use specific UART pins, which you | ||
| can then connect to your computer using: | ||
|
|
||
| - A deducated USB to UART adapter, or | ||
| - An [RP2040 Debug Probe](https://www.raspberrypi.com/products/debug-probe/) or another RP2040 device such as a Raspberry Pi Pico loaded with [debug probe firmware](github.com/raspberrypi/debugprobe). This will work for any UART-capable ESPHome device, not just RP2040 devices. | ||
|
|
||
| If your logs look garbled, make sure that your PC UART interface baud rate is | ||
| the same baud rate as your ESPHome device UART (default is 115200), and that | ||
| both your interface and device have a shared ground connection. | ||
|
|
||
| ### Over MQTT |
| A full example of a `VERBOSE` log message: | ||
| ```c++ | ||
| // Constant TAG placed somewhere in your source or header file | ||
| static const char *const TAG = "component_name"; | ||
| // ... | ||
| ESP_LOGV(TAG, "Received data: %d", recv_data); | ||
| ``` |
| - `ERROR` (`ESP_LOGE()`): Indicates problems that prevent the ESPHome device from working correctly. | ||
| - `WARN` (`ESP_LOGW()`): Warnings are recoverable issues like invalid sensor readings. | ||
| - `INFO` (`ESP_LOGI()`): Informational messages that may be useful to a non-technically savvy user | ||
| - `DEBUG` (`ESP_LOGD()`): Messages that are important for normal device information. |
|
@bluetoothbot review |
PR Review — Improve Logging Documentation with OverviewThe restructure into 🔴 Blocking1. Inaccurate `ESP_LOG*` macro signature (`docs/architecture/logging/overview.md`, L20)The signature Suggested replacement: or, with brief callouts:
2. Truncated sentence describing `TAG` (`docs/architecture/logging/overview.md`, L22)The sentence ends mid-thought: " 🟡 Important1. Backwards framing of log-level configuration (`docs/architecture/logging/overview.md`, L62)Two problems on this line:
Suggested rewrite:
2. Multi-line example has stray `}` and inconsistent indentation (`docs/architecture/logging/overview.md`, L33-45)The snippet opens with no function header but closes with a 3. Debug probe firmware URL missing scheme (`docs/architecture/logging/overview.md`, L87)
4. Incomplete INFO and weak DEBUG descriptions (`docs/architecture/logging/overview.md`, L57-58)Two adjacent issues in the level list:
🟢 Suggestions1. Typo: "deducated" (`docs/architecture/logging/overview.md`, L86)"A deducated USB to UART adapter" → "A dedicated USB to UART adapter". 2. "Channels" vs "levels" — terminology drift (`docs/architecture/logging/overview.md`, L47-53)The section heading is 3. Heading hierarchy inconsistent across transports (`docs/architecture/logging/overview.md`, L64-93)Under
Option 1 will also make the page deep-linkable (e.g. linking to 4. "irregardless" → "regardless" (`docs/architecture/logging/best_practices.md`, L58)"irregardless" is non-standard / a double negative. Use "regardless" in technical documentation. 5. Clarify scope and rationale of the "don't log state changes" rule (`docs/architecture/logging/best_practices.md`, L52-60)Two small improvements would make this guidance land harder:
6. Missing blank line after `## Log Levels` heading (`docs/architecture/logging/overview.md`, L47-48)
Checklist
SummaryThe restructure into Automated review by Kōan0a9a4c1 |
|
@esphbot review |
PR Review — Improve Logging Documentation with OverviewSolid restructure; the earlier critical errors are fixed, only copy-edit polish remains.
🟡 Important1. Missing space: "`DEBUG`level" (`docs/architecture/logging/overview.md`, L66)The inline code span and the following word are run together, so this renders as "DEBUGlevel message types". Add a space after the closing backtick:
🟢 Suggestions1. "irregardless" is non-standard (`docs/architecture/logging/best_practices.md`, L58)Replace "irregardless" with "regardless" — it's widely considered non-standard and reads as an error in documentation. (The Copilot reviewer flagged the same thing.) 2. Scope the "don't log state changes" rule and tie it to performance (`docs/architecture/logging/best_practices.md`, L52-59)The rule says "Component code should not include any log calls for state changes" but the supporting text only mentions "Sensor state changes". aioesphomeapi emits state messages for Two improvements:
3. Missing blank lines around `## Log Levels` heading (`docs/architecture/logging/overview.md`, L50-52)The 4. Terminology drift: "channels" vs "levels" (`docs/architecture/logging/overview.md`, L52)The heading is Checklist
To rebase specific severity levels, mention me: Automated review by Kōan0a9a4c1 |
Summary
This PR adds a high-level overview of the logging framework, intended for developers or advanced users of ESPHome who need a better understanding of the underlying logging framework for development or advanced troubleshooting. I wrote this in response to some challenges I had figuring out how to get serial logs for troubleshooting. The existing logging documentation is moved into a "best practices" page, as that is the topic the existing page mainly covers.
I also added a brief mention in best practices regarding component state change logging (i.e., don't, as it's already covered client-side).
Specific Feedback Requested
For USB to UART, I mention the RP2040 Debug Probe, which I have confirmed works well for getting serial logs on both RP2040 and ESP32 based ESPHome devices. I'm sure there's similar hardware/custom ESP32 firmware that works, but I have no experience with trying any of these out. If there is a specific firmware we can recommend, I think this would be helpful to add.
I've never used MQTT before, and I'm unsure if there's anything to know about MQTT-based logs that don't already apply to network-based logging in general (i.e., it won't work if the network is up, sometimes early pre-network log messages get dropped, etc.)