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

properly handle stdout, stderr, and null #1029

Merged
merged 3 commits into from
Feb 5, 2025
Merged

properly handle stdout, stderr, and null #1029

merged 3 commits into from
Feb 5, 2025

Conversation

osterman
Copy link
Member

@osterman osterman commented Feb 5, 2025

what

Important

This is a partial fix, that ensures logs go to stderr by default
There's still a problem with the presidence order in which flags, envs, and config processes the log settings

why

  • moving to charmbracelet logger (Migrate to Charmbracelet Logger #980), we didn't properly handle common devices
  • logs should always go to stderr by default, so it doesn't mess up github actions or commands that parse output.
  • defaults at some point erroneously changed to /dev/stdout

references

Summary by CodeRabbit

  • Refactor
    • Enhanced the logging system for improved configurability of log output destinations.
    • Updated the default logging behavior to direct messages to standard error instead of standard output.
    • Improved clarity when monitoring log outputs for a more consistent experience.

@osterman osterman requested a review from a team as a code owner February 5, 2025 18:36
@mergify mergify bot added the triage Needs triage label Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

📝 Walkthrough

Walkthrough

The pull request updates the logging configuration across the application. The logging setup in the command’s root file is modified to use a switch statement that selects the log output based on the configured value. Explicit handling for /dev/stderr, /dev/stdout, and /dev/null is added, while any other value triggers an attempt to open a file for logging. The default value for the log file flag and the CLI configuration has been updated from /dev/stdout to /dev/stderr.

Changes

File(s) Change Summary
cmd/root.go, pkg/config/config.go Updated logging configuration: replaced direct comparisons with a switch statement to handle /dev/stderr, /dev/stdout, and /dev/null; changed default from /dev/stdout to /dev/stderr.
tests/fixtures/scenarios/valid-log-level/atmos.yaml, tests/snapshots/TestCLICommands_Valid_Log_Level_in_Config_File.stderr.golden, tests/snapshots/TestCLICommands_Valid_Log_Level_in_Environment_Variable.stderr.golden, tests/snapshots/TestCLICommands_atmos_--help.stdout.golden, tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden, tests/snapshots/TestCLICommands_atmos_validate_editorconfig_help.stdout.golden Updated log file output from /dev/stdout to /dev/stderr in various test scenarios and documentation. Added debug log statements for visibility in test snapshots.

Assessment against linked issues

Objective Addressed Explanation
Sync the default value for logs.file with atmos.yaml (#1028)
Avoid logging bug in #1026 The changes do not directly address the logging bug.

Possibly related PRs

Suggested labels

minor

Suggested reviewers

  • aknysh

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19f84b4 and 77b6106.

📒 Files selected for processing (1)
  • tests/test-cases/log-level-validation.yaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (1)
tests/test-cases/log-level-validation.yaml (1)

54-55: Clarify the Debug Statement in the Config Test Case

The new debug output "DEBU Using command line argument" appears in the "Valid Log Level in Config File" test case, yet the inline comment notes that no log level is passed via the command line. This causes a discrepancy between the expected source of the log level and the debug message shown. Please verify whether the debug output should reflect the configuration file’s log level or if the test case description should be updated.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
@mergify mergify bot removed the triage Needs triage label Feb 5, 2025
aknysh
aknysh previously approved these changes Feb 5, 2025
@aknysh aknysh added the patch A minor, backward compatible change label Feb 5, 2025
@osterman osterman dismissed stale reviews from aknysh and coderabbitai[bot] via 19f84b4 February 5, 2025 21:57
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: 0

🧹 Nitpick comments (1)
tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden (1)

78-78: Simplify example usage by removing unnecessary parameters.

Based on previous feedback, the example usage should not include <component> and -s <stack> parameters as they are not applicable to the editorconfig validation command.

-  atmos validate editorconfig  <component> -s <stack> -- <native-flags>
+  atmos validate editorconfig -- <native-flags>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d8d93e and 19f84b4.

📒 Files selected for processing (6)
  • tests/fixtures/scenarios/valid-log-level/atmos.yaml (1 hunks)
  • tests/snapshots/TestCLICommands_Valid_Log_Level_in_Config_File.stderr.golden (1 hunks)
  • tests/snapshots/TestCLICommands_Valid_Log_Level_in_Environment_Variable.stderr.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig_help.stdout.golden (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/snapshots/TestCLICommands_Valid_Log_Level_in_Config_File.stderr.golden
🧰 Additional context used
📓 Learnings (2)
tests/snapshots/TestCLICommands_atmos_--help.stdout.golden (1)
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.
tests/snapshots/TestCLICommands_atmos_validate_editorconfig_help.stdout.golden (1)
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (6)
tests/snapshots/TestCLICommands_Valid_Log_Level_in_Environment_Variable.stderr.golden (1)

3-3: LGTM! Debug output correctly reflects stderr logging.

The debug output accurately shows the updated log file configuration, which aligns with the PR's objective to properly handle stderr output.

tests/snapshots/TestCLICommands_atmos_--help.stdout.golden (1)

42-42: LGTM! Help text accurately reflects stderr as default.

The help text properly documents the updated default value while maintaining clear information about all supported file descriptors.

tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden (1)

61-61: LGTM! Help text correctly shows stderr as default.

The help text properly reflects the updated default value for the logs-file flag.

tests/snapshots/TestCLICommands_atmos_validate_editorconfig_help.stdout.golden (1)

61-61: Same issues as previous file.

The help text has the same changes and considerations as the previous file.

Also applies to: 78-78

tests/fixtures/scenarios/valid-log-level/atmos.yaml (2)

3-3: Refined Log Output Redirection

Changing the default log file from /dev/stdout to /dev/stderr aligns with the intended logging behavior to ensure that logs do not interfere with output parsing (especially in CI environments). This update properly meets the PR objective.


8-8: Wildcard Pattern for Included Paths

The inclusion of the wildcard "**/*" under included_paths appears intended to capture all relevant files. Please verify that this broad pattern does not inadvertently include files that should be excluded, particularly in larger codebases.

If needed, I can suggest refined patterns or filters to better target desired files.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
@aknysh aknysh merged commit 7d202f6 into main Feb 5, 2025
44 checks passed
@aknysh aknysh deleted the fix-logoutput branch February 5, 2025 23:08
@coderabbitai coderabbitai bot mentioned this pull request Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 2025

These changes were released in v1.160.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird escape code issues with v1.158.0
2 participants