Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[configurator] Expose log level env variable #3845

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mueslo
Copy link

@mueslo mueslo commented Nov 28, 2024

It would be nice to reduce unnecessary logspam, e.g. that every single HTTP request gets logged in the default 'info' loglevel of hass-configurator, with no easy way to fix this. And it does indeed have a loglevel flag ( https://github.com/danielperna84/hass-configurator/blob/397bda2f9131d2c1c979bf01391745699852b049/hass_configurator/configurator.py#L105 ) that is however not exposed in the Home Assistant addon configuration.

Summary by CodeRabbit

  • New Features

    • Introduced a configurable log level, allowing users to adjust logging verbosity.
    • Added a new optional configuration option loglevel for the "File editor" add-on.
  • Documentation

    • Updated changelog to reflect the new version 5.8.1 and the addition of the loglevel feature.
    • Enhanced documentation for the "File editor" add-on to include the new loglevel option.
  • Configuration Updates

    • Updated configuration file to include the new loglevel option with a default value of 'info'.

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new version, 5.8.1, for the configurator, which includes the feature of a configurable log level. The documentation and configuration files have been updated to reflect this new option, allowing users to specify their desired logging verbosity. The updates also include a new environment variable in the script that manages logging behavior. The overall structure of the documentation and configuration files remains largely unchanged, focusing on enhancing user control over logging settings.

Changes

File Change Summary
configurator/CHANGELOG.md Added new version entry ## 5.8.1 and documented feature Expose configurable log level.
configurator/DOCS.md Updated documentation for "File editor" to include new optional configuration option loglevel.
configurator/config.yaml Updated version from 5.8.0 to 5.8.1, added new option loglevel: info, and defined schema.
configurator/rootfs/etc/s6-overlay/s6-rc.d/configurator/run Introduced new environment variable HC_LOGLEVEL based on loglevel configuration.
configurator/translations/en.yaml Added new configuration option loglevel with name and description fields.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 or @coderabbitai title 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.

Copy link
Contributor

@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: 3

🧹 Outside diff range and nitpick comments (2)
configurator/translations/en.yaml (1)

28-31: Enhance the log level description

The addition of the log level configuration option is good, but the description could be more helpful to users.

Consider expanding the description to be more informative:

   loglevel:
     name: Log level
     description: >-
-      The log level to use (default `info`).
+      Specify the logging verbosity. Available levels from most to least verbose:
+      `debug`, `info` (default), `warning`, `error`, `critical`. Setting a higher
+      level reduces log output. For example, `warning` will only show warning and
+      error messages.
configurator/CHANGELOG.md (1)

3-5: Enhance the changelog entry with more specific details.

The changelog entry is clear but could be more informative. Consider expanding it to include the default value and available options:

 ## 5.8.1
 
-Expose configurable log level
+Expose configurable log level (default: 'info', options: debug/info/warning/error/critical)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9cb42 and d4651f8.

📒 Files selected for processing (5)
  • configurator/CHANGELOG.md (1 hunks)
  • configurator/DOCS.md (1 hunks)
  • configurator/config.yaml (3 hunks)
  • configurator/rootfs/etc/s6-overlay/s6-rc.d/configurator/run (2 hunks)
  • configurator/translations/en.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
configurator/CHANGELOG.md (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

configurator/DOCS.md (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

configurator/config.yaml (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

🔇 Additional comments (4)
configurator/config.yaml (2)

2-2: LGTM: Version bump follows semantic versioning

The minor version increment is appropriate for adding a new configuration option.


46-46: LGTM: Log level schema is well-defined

The schema correctly defines the standard Python logging levels in order of verbosity, ensuring type safety through enumeration.

configurator/rootfs/etc/s6-overlay/s6-rc.d/configurator/run (2)

10-10: LGTM! Export declaration follows established patterns

The HC_LOGLEVEL export declaration is consistent with other environment variable exports and follows the existing naming convention.


Line range hint 10-36: Verify configurator's handling of HC_LOGLEVEL

Let's ensure that:

  1. The configurator code actually uses this environment variable
  2. The documentation properly explains the available log levels
✅ Verification successful

Let me check the actual content of these files to verify how HC_LOGLEVEL is used and documented.


HC_LOGLEVEL implementation is properly documented and configured

The verification shows that:

  • The loglevel option is well documented in DOCS.md with a clear description
  • The config schema correctly defines allowed values: debug, info, warning, error, critical
  • The option is properly translated in en.yaml with a clear name and description
  • The environment variable HC_LOGLEVEL is exported and set with the configured value, defaulting to 'info'
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if configurator code references HC_LOGLEVEL
rg -l "HC_LOGLEVEL|loglevel" configurator/

# Check if documentation mentions the new option
rg -l "loglevel" configurator/DOCS.md configurator/config.yaml configurator/CHANGELOG.md

Length of output: 319


Script:

#!/bin/bash
# Check the documentation of loglevel
echo "=== DOCS.md ==="
rg -A 5 "loglevel" configurator/DOCS.md

echo -e "\n=== config.yaml ==="
rg -A 5 "loglevel" configurator/config.yaml

echo -e "\n=== translations/en.yaml ==="
rg -A 5 "loglevel" configurator/translations/en.yaml

echo -e "\n=== Looking for HC_LOGLEVEL usage in configurator ==="
rg "HC_LOGLEVEL" configurator/

Length of output: 1122

@@ -33,6 +33,7 @@ options:
- .storage
- deps
ssh_keys: []
loglevel: info
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 28, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider changing default log level to 'warning'

The PR's objective is to reduce "logspam" from HTTP request logging at 'info' level. However, keeping 'info' as the default maintains the same verbose logging behavior. Consider defaulting to 'warning' to address the stated problem while allowing users to opt-in to more verbose logging if needed.

-  loglevel: info
+  loglevel: warning
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
loglevel: info
loglevel: warning

Copy link
Author

Choose a reason for hiding this comment

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

For now the PR was only meant to allow the user to reduce logging verbosity and not change defaults. If maintainers agree I am very happy to set it to 'warning' instead, though. It is really unnecessary to log http requests by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mueslo Exposing the log level configuration without changing the default maintains current behavior, allowing users to adjust logging verbosity as needed.

Comment on lines +35 to +36
bashio::config.has_value 'loglevel' \
&& HC_LOGLEVEL="$(bashio::config 'loglevel')" || HC_LOGLEVEL=info
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improvements to the log level configuration

  1. The default level of 'info' doesn't address the PR's objective of reducing logspam. Consider defaulting to 'warning' instead.
  2. There's no validation of allowed log levels, which could lead to runtime errors if invalid values are provided.
  3. The syntax could be simplified using bashio::config.get with a default value.

Consider this alternative implementation:

-bashio::config.has_value 'loglevel' \
-    && HC_LOGLEVEL="$(bashio::config 'loglevel')" || HC_LOGLEVEL=info
+# Validate log level
+LOGLEVEL="$(bashio::config.get 'loglevel' 'warning')"
+if [[ ! "${LOGLEVEL}" =~ ^(debug|info|warning|error|critical)$ ]]; then
+    bashio::log.error "Invalid log level: ${LOGLEVEL}"
+    bashio::log.error "Valid options are: debug, info, warning, error, critical"
+    bashio::exit.nok
+fi
+HC_LOGLEVEL="${LOGLEVEL}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bashio::config.has_value 'loglevel' \
&& HC_LOGLEVEL="$(bashio::config 'loglevel')" || HC_LOGLEVEL=info
# Validate log level
LOGLEVEL="$(bashio::config.get 'loglevel' 'warning')"
if [[ ! "${LOGLEVEL}" =~ ^(debug|info|warning|error|critical)$ ]]; then
bashio::log.error "Invalid log level: ${LOGLEVEL}"
bashio::log.error "Valid options are: debug, info, warning, error, critical"
bashio::exit.nok
fi
HC_LOGLEVEL="${LOGLEVEL}"

Comment on lines +57 to +60
### Option: `loglevel` (optional)

The loglevel to pass to hass-configurator (default 'info').

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance the loglevel option documentation

The documentation for the loglevel option needs more detail to help users make informed decisions.

Apply this diff to improve the documentation:

 ### Option: `loglevel` (optional)
 
-The loglevel to pass to hass-configurator (default 'info').
+Specify the log level for the File editor add-on. Valid values:
+
+- `debug`: Show all logs, including detailed debugging information
+- `info`: Show informational messages, warnings, and errors (default)
+- `warning`: Show only warning and error messages
+- `error`: Show only error messages
+- `critical`: Show only critical error messages
+
+Set to `warning` or higher to reduce log volume from HTTP requests.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Option: `loglevel` (optional)
The loglevel to pass to hass-configurator (default 'info').
### Option: `loglevel` (optional)
Specify the log level for the File editor add-on. Valid values:
- `debug`: Show all logs, including detailed debugging information
- `info`: Show informational messages, warnings, and errors (default)
- `warning`: Show only warning and error messages
- `error`: Show only error messages
- `critical`: Show only critical error messages
Set to `warning` or higher to reduce log volume from HTTP requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant