Skip to content

feature: standardize logger used in endure and RR#181

Merged
rustatian merged 1 commit into
masterfrom
feature/update-logger
Aug 31, 2024
Merged

feature: standardize logger used in endure and RR#181
rustatian merged 1 commit into
masterfrom
feature/update-logger

Conversation

@rustatian

@rustatian rustatian commented Aug 31, 2024

Copy link
Copy Markdown
Member

Reason for This PR

  • Standardize logger

Description of Changes

  • Replace slog logger used in endure with zap to use the same logger in RR and Endure.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Introduced a new logging system using the zap library, enhancing structured logging capabilities across the application.
    • Added a new logging framework in the logger package, allowing for flexible configuration based on environment.
  • Bug Fixes

    • Improved error handling and logging consistency in various methods by transitioning to the zap logging package.
  • Chores

    • Updated dependencies in the project to include go.uber.org/zap and related packages for improved logging functionality.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added the C-Enhancement Category: enhancement label Aug 31, 2024
@rustatian rustatian requested a review from wolfy-j August 31, 2024 10:50
@rustatian rustatian self-assigned this Aug 31, 2024
@coderabbitai

coderabbitai Bot commented Aug 31, 2024

Copy link
Copy Markdown

Walkthrough

The changes involve a significant update to the logging framework across multiple files, transitioning from the log/slog library to go.uber.org/zap. This update includes modifications to the logger instantiation and logging calls within various methods and files. Additionally, adjustments were made to the .golangci.yml configuration file, replacing certain linters and removing others, reflecting a shift in linting strategy. New dependencies were also added to the go.mod file to support these changes.

Changes

Files Change Summary
.golangci.yml Replaced exportloopref with copyloopvar and removed goconst.
edges.go, endure.go, init.go, poller.go, serve.go, stop.go Replaced log/slog with go.uber.org/zap for logging, updating log calls accordingly.
go.mod Added new dependencies: github.com/fatih/color, go.uber.org/zap, and several indirect dependencies.
logger/zap.go Introduced a new file implementing a logging system using the Zap library, including functions for logger configuration and colorized output.
options.go Removed the LogHandler function and import for log/slog.
graph/vertex.go Minor comment documentation change for the Vertex struct.

Sequence Diagram(s)

sequenceDiagram
    participant A as Client
    participant B as Endure
    participant C as Logger

    A->>B: Request action
    B->>C: Log action start
    C-->>B: Log confirmation
    B->>A: Return response
Loading

🐇 In the meadow, a change has come,
With logging bright, we hop and run!
From slog to zap, our tales now sing,
Structured logs, oh what joy they bring!
Hopping high, we celebrate,
In code and cheer, we elevate! 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ec599c and a6e0602.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • go.work.sum is excluded by !**/*.sum
Files selected for processing (11)
  • .golangci.yml (1 hunks)
  • edges.go (7 hunks)
  • endure.go (9 hunks)
  • go.mod (1 hunks)
  • graph/vertex.go (1 hunks)
  • init.go (4 hunks)
  • logger/zap.go (1 hunks)
  • options.go (2 hunks)
  • poller.go (3 hunks)
  • serve.go (2 hunks)
  • stop.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • graph/vertex.go
Additional comments not posted (24)
go.mod (5)

8-8: Approved addition of github.com/fatih/color.

This dependency is likely added to enhance color output capabilities, which can improve the readability of logs or other outputs.


10-10: Approved addition of go.uber.org/zap.

This dependency is central to the PR's objective of standardizing the logging framework across the Endure and RR projects.


14-14: Approved addition of github.com/mattn/go-colorable.

This indirect dependency is likely required by github.com/fatih/color for proper functioning on different platforms.


15-15: Approved addition of github.com/mattn/go-isatty.

This indirect dependency is likely required for detecting whether the output is a TTY, which is useful for color output.


16-16: Approved addition of go.uber.org/multierr.

This indirect dependency is likely required by go.uber.org/zap for handling multiple errors in a structured way, enhancing error management in logging.

stop.go (2)

49-49: Approved: Updated logging statement.

The transition to zap.String for logging the plugin ID is consistent with the PR's objective to standardize logging across projects.


57-57: Approved: Enhanced error logging.

The use of zap.String and zap.Error in the error logging statement provides clearer and more contextual information, which is beneficial for debugging and monitoring.

serve.go (1)

42-42: Approved: Updated logging statement.

The transition to zap.String for logging the plugin ID is consistent with the PR's objective to standardize logging across projects.

.golangci.yml (2)

44-44: Approved: Linter replacement.

Replacing exportloopref with copyloopvar reflects a strategic shift in linting focus, which is consistent with the PR's objectives to enhance code quality.


44-44: Approved: Linter removal.

The removal of goconst may reflect a strategic decision to focus on other aspects of code quality, aligning with the PR's objectives.

edges.go (2)

24-26: Logging changes are appropriate but consider adding more context.

The transition from slog to zap logging is correctly implemented. However, consider adding more context to the logs, such as including additional details about the operation or the state of the application at this point, which could be useful for debugging.


51-52: Logging changes are appropriate but consider adding more context.

The transition from slog to zap logging is correctly implemented. However, consider adding more context to the logs, such as including additional details about the operation or the state of the application at this point, which could be useful for debugging.

Also applies to: 81-82

init.go (1)

46-46: Logging changes are appropriate but consider adding more context.

The transition from slog to zap logging is correctly implemented. However, consider adding more context to the logs, such as including additional details about the operation or the state of the application at this point, which could be useful for debugging.

Also applies to: 95-103

logger/zap.go (2)

21-125: Review of BuildLogger: Configuration appears correct but needs validation.

The BuildLogger function correctly sets up the zap logger configurations based on the provided logging level. However, it would be beneficial to add unit tests to validate that the logger is configured as expected for different scenarios.


128-151: Review of color encoding functions: Correct implementation but consider edge cases.

The ColoredLevelEncoder and ColoredNameEncoder functions correctly apply colors to log levels and names. However, consider handling edge cases where the log level or name might not fit the expected criteria, ensuring that the application does not crash or behave unexpectedly.

endure.go (4)

13-16: Update import statements to reflect logger changes.

The import statements have been updated to include go.uber.org/zap and remove log/slog. This change is necessary to support the transition from slog to zap logging frameworks. Ensure that all references to the slog library are removed from the codebase to avoid compilation errors.


28-28: Update the logger type in the Endure struct.

The log field in the Endure struct has been changed from *slog.Logger to *zap.Logger. This change is crucial for the integration of the zap logger throughout the project. It's important to verify that all methods on the Endure struct that utilize this logger have been appropriately updated to use zap methods.


38-38: Clarify the purpose of the Options type.

The comment for the Options type has been slightly modified for clarity. While this change does not affect the functionality, it improves the readability and understanding of the code. Always ensure that comments are updated to reflect the current state of the code accurately.


Line range hint 97-108: Update logging calls to use zap methods.

The logging calls within the Register method have been updated to use zap methods such as zap.String, zap.Uint64, and zap.Error. These changes are necessary to align with the new logging framework. Ensure that the log levels and methods used are appropriate for the messages being logged. For instance, using Warn for already registered plugins and Debug for registration details is appropriate and helps in filtering log messages based on severity.

Also applies to: 119-121, 142-144

options.go (3)

Line range hint 5-8: GracefulShutdownTimeout function review: Approved.

The function is self-contained and does not directly interact with logging functionalities. The changes in logging strategy do not appear to impact this function.


Line range hint 10-13: Visualize function review: Approved.

This function enables visualization settings and does not interact with logging functionalities. It remains unaffected by the changes in the logging strategy.


Line range hint 15-18: EnableProfiler function review: Approved.

The function is designed to enable profiling and does not involve logging functionalities. It remains unaffected by the changes in the logging strategy.

poller.go (2)

Line range hint 14-20: Updated logging in poll function: Approved.

The transition to zap for logging in this function is correctly implemented. The use of structured logging with zap.Error and zap.String enhances the logging capabilities and aligns with the new logging strategy.


Line range hint 27-33: Updated logging in startMainThread function: Approved.

The transition to zap for debug logging in this function is correctly implemented. The use of structured logging with zap.String ensures consistency across the application and aligns with the new logging strategy.

Comment thread endure.go
@rustatian rustatian merged commit 6668f55 into master Aug 31, 2024
@rustatian rustatian deleted the feature/update-logger branch August 31, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Enhancement Category: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant