-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
WalkthroughThese updates enhance the UberTask module by integrating a robust logging system that defaults to Changes
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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
What does this PR do?
This PR adds usage of configurable
logger
which replacesputs
. STDOUT logger is used by defaultSummary by CodeRabbit
New Features
Rails.logger
or falls back to a custom logger ifRails.logger
is unavailable.Bug Fixes
Tests