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

Add configurable logger usage #14

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

zzaakiirr
Copy link
Collaborator

@zzaakiirr zzaakiirr commented Jul 8, 2024

What does this PR do?
This PR adds usage of configurable logger which replaces puts. STDOUT logger is used by default

Summary by CodeRabbit

  • New Features

    • Introduced a dynamic logger setup in the app, which defaults to Rails.logger or falls back to a custom logger if Rails.logger is unavailable.
  • Bug Fixes

    • Updated trace message handling to use the logger's debug level, ensuring consistent logging behavior.
  • Tests

    • Added tests for the new logger functionality to verify correct logger initialization and behavior.
    • Updated existing tests to reflect changes in trace message logging.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

These updates enhance the UberTask module by integrating a robust logging system that defaults to Rails.logger but can fallback to a standard logger. The logging enhancement ensures trace messages are logged consistently. Additionally, new test cases are introduced to validate the logger's behavior, promoting more reliable debugging and trace management within the module.

Changes

File Path Change Summary
lib/uber_task.rb Added dynamic logger method and attr_writer to manage logging within UberTask.
lib/uber_task/internal.rb Updated trace method to use UberTask.logger.debug instead of direct printing.
spec/uber_task/internal_spec.rb Modified test cases to verify trace messages are logged at debug level instead of using puts.
spec/uber_task/logger_spec.rb Introduced tests to validate logger functionality, including proper fallback and dynamic setting behaviors.

Sequence Diagram(s)

sequenceDiagram
    participant ExternalCaller
    participant UberTask
    participant Logger

    ExternalCaller->>UberTask: Call method that triggers trace
    UberTask->>UberTask: Check for logger presence
    alt Rails.logger available
        UberTask->>Logger: Log trace message using Rails.logger
    else Rails.logger not available
        UberTask->>Logger: Create new Logger instance
        UberTask->>Logger: Log trace message using default logger
    end
    Logger-->>UberTask: Confirmation of logged message
    UberTask-->>ExternalCaller: Return from method call
Loading

Poem

In the code where logs reside,
We bring the changes with great pride.
Swapping puts for logger's gleam,
More robust than it may seem.
Now our traces, clear and bright,
Make debugging a delight!
🐇📜✨


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a7b09b9 and 795147b.

Files selected for processing (4)
  • lib/uber_task.rb (1 hunks)
  • lib/uber_task/internal.rb (1 hunks)
  • spec/uber_task/internal_spec.rb (1 hunks)
  • spec/uber_task/logger_spec.rb (1 hunks)
Files skipped from review due to trivial changes (1)
  • lib/uber_task/internal.rb
Additional comments not posted (6)
spec/uber_task/internal_spec.rb (1)

38-41: LGTM! The change correctly uses the logger's debug level.

The test now verifies that the trace message is logged using the logger's debug level instead of puts.

spec/uber_task/logger_spec.rb (3)

9-15: LGTM! The test correctly verifies memoization of the logger.

The test ensures that the logger instance is memoized and not recreated.


17-22: LGTM! The test correctly verifies the default logger behavior.

The test ensures that the logger defaults to stdout and correctly logs messages when Rails.logger is not defined.


26-36: LGTM! The test correctly verifies changing the logger.

The test ensures that the logger can be changed and the new logger is used instead of the old one.

lib/uber_task.rb (2)

19-26: LGTM! The logger method is well-implemented.

The method ensures that the logger is memoized and defaults to Rails.logger if available, otherwise falls back to a new logger instance with stdout.


17-17: LGTM! The logger writer method is well-implemented.

The method allows changing the logger instance.

@@ -5,8 +5,7 @@ module Internal
def self.trace
return unless Thread.current[:__uber_task_trace__]

message = yield
puts message
UberTask.logger.debug yield
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not quite sure that debug level should be used - maybe info is more appropriate

@borela WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Debug level sounds good, this tracing is only useful when debugging otherwise it will spam a lot as it enter/exits a task.

)
end

context 'when Rails logger is not defined' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Next PR I'm working on will introduce tests in Rails application environment and context 'when Rails logger is defined' will be added

@borela borela merged commit d92f0da into shakacode:main Jul 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants