Skip to content

Use stdout for logging output#169

Merged
frenck merged 1 commit intohassio-addons:mainfrom
sairon:log-to-stdout
Sep 11, 2025
Merged

Use stdout for logging output#169
frenck merged 1 commit intohassio-addons:mainfrom
sairon:log-to-stdout

Conversation

@sairon
Copy link
Collaborator

@sairon sairon commented Jul 31, 2025

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

  • Refactor
    • Updated logging functions so that all log messages are now output to standard output instead of standard error.

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.
@coderabbitai
Copy link

coderabbitai bot commented Jul 31, 2025

Walkthrough

The update modifies all logging functions in lib/log.sh to remove redirection of log output from standard error (stderr) to standard output (stdout). All echo -e ... >&2 commands are now simply echo -e ..., affecting base and color-specific log functions. No other logic or flow is changed.

Changes

Cohort / File(s) Change Summary
Logging Output Redirection Update
lib/log.sh
Removed all >&2 redirections from echo -e commands, so log output now goes to stdout instead of stderr.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A bunny hopped to logs anew,
Redirects gone, the path is true.
No more stderr’s winding way,
All stdout, both night and day.
Simpler prints, a cleaner view—
That’s the magic rabbits do! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sairon sairon mentioned this pull request Jul 31, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
lib/log.sh (1)

118-118: Same stdout redirection change applies here

The concern about stdout pollution raised for bashio::log also applies to bashio::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 stderr

Redirecting 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 jq consumers) will now receive interleaved log lines.
Please audit all add-ons that source bashio to 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
+fi

This keeps the new default while providing an escape hatch.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d0a2f7 and 66cf0a6.

📒 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 good

All 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

@github-actions
Copy link

github-actions bot commented Sep 5, 2025

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.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Sep 5, 2025
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @sairon 👍

../Frenck

@frenck frenck merged commit b1ae1ce into hassio-addons:main Sep 11, 2025
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementors. label Sep 11, 2025
PaulSD added a commit to PaulSD/bashio that referenced this pull request Sep 21, 2025
PaulSD added a commit to PaulSD/bashio that referenced this pull request Sep 23, 2025
PaulSD added a commit to PaulSD/bashio that referenced this pull request Sep 23, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementors. stale There has not been activity on this issue or PR for quite some time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants