Use stdout for logging output#169
Conversation
Use stdout instead of stderr for outputting messages. While using stderr is default e.g. in Python as well, using it for add-ons makes the logs in Home Assistant OS (which uses Docker with journald log driver) to be logged with err priority (level 3) to the Systemd Journal. Moreover, as a result of using different pipe than stdout, mixing standard output (e.g. echo commands) with bashio logging might result in the add-on output being printed out of order once the pipes are printed next to each other, unless the output has been printed to stderr as well. This can cause confusion, as seen in hassio-addons#154.
WalkthroughThe update modifies all logging functions in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
lib/log.sh (1)
118-118: Same stdout redirection change applies hereThe concern about stdout pollution raised for
bashio::logalso applies tobashio::log.log. Refer to the earlier comment for mitigation options.
🧹 Nitpick comments (1)
lib/log.sh (1)
18-18: Potential backward-compatibility break: logs are no longer emitted on stderrRedirecting logs to stdout will satisfy the Home-Assistant/journald requirement, but every script or tool that currently parses stdout (e.g. JSON/YAML generators or
jqconsumers) will now receive interleaved log lines.
Please audit all add-ons that sourcebashioto ensure they don’t rely on “clean” stdout.Optional hardening:
-echo -e "${message}" +# Allow opt-in revert for legacy consumers +if [[ -z "${BASHIO_LOG_TO_STDERR:-}" ]]; then + echo -e "${message}" +else + echo -e "${message}" >&2 +fiThis keeps the new default while providing an escape hatch.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/log.sh(8 hunks)
🔇 Additional comments (1)
lib/log.sh (1)
30-30: Consistent change across color helpers – looks goodAll color-specific helpers were updated in line with the base logger. No additional issues spotted.
Also applies to: 42-42, 54-54, 66-66, 78-78, 90-90
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions. |
Fixes issues introduced by hassio-addons#169
Fixes issues introduced by hassio-addons#169
Fixes issues introduced by hassio-addons#169
Proposed Changes
Use stdout instead of stderr for outputting messages. While using stderr is default e.g. in Python as well, using it for add-ons makes the logs in Home Assistant OS (which uses Docker with journald log driver) to be logged with err priority (level 3) to the Systemd Journal.
Moreover, as a result of using different pipe than stdout, mixing standard output (e.g. echo commands) with bashio logging might result in the add-on output being printed out of order once the pipes are printed next to each other, unless the output has been printed to stderr as well. This can cause confusion, as seen in #154.
Related Issues
Summary by CodeRabbit