atmos icon indicating copy to clipboard operation
atmos copied to clipboard

Refactor logging to structured semantics

Open osterman opened this issue 8 months ago โ€ข 2 comments

Summary

  • use Charmbracelet logger directly instead of u.Log* helpers
  • replace log.Warnf and fmt.Sprintf calls with structured fields

Testing

  • make lint (fails: can't load config)
  • make testacc-cover (interrupted: took too long)
  • go test ./... (interrupted: build in progress)

https://chatgpt.com/codex/tasks/task_b_68547188e9808332b49ab4a4a42afb1a

Summary by CodeRabbit

  • Refactor
    • Improved logging consistency by adopting structured logging for warnings and errors across the application, enhancing message clarity without affecting user experience.
  • Tests
    • Added tests for temporary file management, handling of unsupported archive types, and cache update frequency to ensure robustness and reliability.

osterman avatar Jun 19 '25 23:06 osterman

๐Ÿ“ Walkthrough

Walkthrough

All warning and error log statements previously using a custom utility logger have been updated to use the structured logging methods from the github.com/charmbracelet/log package. This affects multiple files, ensuring consistent, structured logging throughout the codebase. No functional or control flow changes were made. Additionally, new tests were added for tar header processing, temporary directory and file handling, and cache frequency parsing and update checks.

Changes

Files / Grouped Paths Change Summary
cmd/cmd_utils.go Replaced u.LogWarning with log.Warn for warnings, using structured key-value pairs for error details.
cmd/docs.go, cmd/root.go Updated deprecated configuration and config-not-found warnings to use log.Warn instead of u.LogWarning.
internal/exec/file_utils.go Changed u.LogWarning/u.LogError to log.Warn/log.Error with structured logging for file and temp dir errors.
internal/exec/helmfile.go Swapped u.LogWarning for log.Warn in cleanup warning logs.
internal/exec/tar_utils.go Converted log.Warnf to log.Warn with structured key-value pairs for unsupported tar file types.
pkg/config/cache.go Replaced u.LogWarning with log.Warn for unsupported frequency warnings, using structured logging.
pkg/utils/hcl_utils.go Updated deferred file close warnings to use log.Warn instead of LogWarning.
internal/exec/file_utils_test.go Added test TestRemoveTempDirAndCloseFile to verify temp directory removal and file closing behavior.
internal/exec/tar_utils_test.go Added test TestProcessTarHeaderUnsupportedType to verify handling of unsupported tar header types without errors.
pkg/config/cache_frequency_test.go Added tests for parseFrequency and ShouldCheckForUpdates functions covering various input scenarios and outcomes.

Suggested labels

minor


๐Ÿ“œ 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 0d3aea73f866b941ffee7a54ddb3737037787603 and 0b3113053ecca3f141dee7fa983f63475f698ca9.

๐Ÿ“’ Files selected for processing (2)
  • internal/exec/file_utils_test.go (1 hunks)
  • pkg/config/cache_frequency_test.go (1 hunks)
โœ… Files skipped from review due to trivial changes (1)
  • pkg/config/cache_frequency_test.go
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • internal/exec/file_utils_test.go
โฐ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
โœจ Finishing Touches
  • [ ] ๐Ÿ“ Generate Docstrings
๐Ÿงช Generate Unit Tests
  • [ ] Create PR with Unit Tests
  • [ ] Post Copyable Unit Tests in Comment
  • [ ] Commit Unit Tests in branch codex/audit-and-update-logging-conventions

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 auto-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 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] avatar Jun 19 '25 23:06 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 57.69231% with 11 lines in your changes missing coverage. Please review.

Project coverage is 50.31%. Comparing base (913fe03) to head (0b31130). Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
cmd/cmd_utils.go 0.00% 4 Missing :warning:
cmd/docs.go 0.00% 2 Missing :warning:
pkg/utils/hcl_utils.go 0.00% 2 Missing :warning:
cmd/root.go 0.00% 1 Missing :warning:
internal/exec/file_utils.go 83.33% 1 Missing :warning:
internal/exec/helmfile.go 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1321      +/-   ##
==========================================
- Coverage   50.66%   50.31%   -0.36%     
==========================================
  Files         237      237              
  Lines       25777    25789      +12     
==========================================
- Hits        13061    12975      -86     
- Misses      11085    11197     +112     
+ Partials     1631     1617      -14     
Flag Coverage ฮ”
unittests 50.31% <57.69%> (-0.36%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jun 19 '25 23:06 codecov[bot]