-
Notifications
You must be signed in to change notification settings - Fork 1
fix(agent): apply the configured logger_level to the default logger #376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/forest_admin_agent/spec/lib/forest_admin_agent/services/logger_service_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| require 'spec_helper' | ||
|
|
||
| module ForestAdminAgent | ||
| module Services | ||
| describe LoggerService do | ||
| describe 'default logger level' do | ||
| it 'defaults to Info' do | ||
| service = described_class.new | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::INFO) | ||
| end | ||
|
|
||
| it 'applies the configured level to the default logger' do | ||
| service = described_class.new('Warn') | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::WARN) | ||
| end | ||
|
|
||
| it 'is case-insensitive, so the config-style lowercase levels work too' do | ||
| service = described_class.new('debug') | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::DEBUG) | ||
| end | ||
|
|
||
| it 'falls back to Info when given an unknown level' do | ||
| service = described_class.new('nonsense') | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::INFO) | ||
| end | ||
|
|
||
| it 'supports Fatal, the quietest level' do | ||
| service = described_class.new('Fatal') | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::FATAL) | ||
| end | ||
|
|
||
| it 'supports Unknown' do | ||
| service = described_class.new('Unknown') | ||
|
|
||
| expect(service.default_logger.level).to eq(Logger::UNKNOWN) | ||
| end | ||
| end | ||
|
|
||
| describe '#log' do | ||
| it 'filters out messages below the configured level on the default logger' do | ||
| # MonoLogger captures the $stdout object at construction time, so the service | ||
| # has to be built inside the block for RSpec's stdout swap to reach its writes. | ||
| expect do | ||
| described_class.new('Warn').log('Info', 'hidden') | ||
| end.not_to output(/hidden/).to_stdout | ||
| end | ||
|
|
||
| it 'still emits messages at or above the configured level' do | ||
| expect do | ||
| described_class.new('Warn').log('Warn', 'shown') | ||
| end.to output(/shown/).to_stdout | ||
| end | ||
|
|
||
| it 'delegates to a custom logger regardless of logger_level' do | ||
| custom_logger = 'proc { |severity, message| $stdout.puts "custom:#{severity}:#{message}" }' # rubocop:disable Lint/InterpolationCheck | ||
| service = described_class.new('Error', custom_logger) | ||
|
|
||
| expect { service.log('Info', 'hello') }.to output(/custom:1:hello/).to_stdout | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If it's FATAL, we translate it to INFO; so, instead of aiming for less verbosity, we end up with maximum verbosity.