Setting `log_level` to `:error` does not stop Aws client from outputting
jshah opened this issue · 9 comments
The README
says:
The AWS SDK is configured to use the built-in Rails logger for any SDK log output. The logger is configured to use the :info log level. You can change the log level by setting :log_level in the Aws.config hash.
Aws.config.update(log_level: :debug)
However, setting to :error
: Aws.config.update(log_level: :error)
does not stop the Aws
clients from outputting :info
logs.
[Aws::SecretsManager::Client 200 0.204598 0 retries] get_secret_value(secret_id: <hidden>)
Only setting the logger to nil
works:
Aws.config.update(logger: nil)
I would assume setting Aws.config.log_level
would apply to all Aws
modules. Is this the recommended way? Can we update docs to reflect what is recommended here?
Thanks for opening an issue. It should be applying to all Aws modules. What Rails version are you using?
aws-sdk-rails will set Rails.logger
to Aws.config -
aws-sdk-rails/lib/aws/rails/railtie.rb
Lines 39 to 43 in d59a29a
Could you also tell me what Rails.logger
resolves to?
We are on Rails version 6.1.6.1
.
This is what Rails.logger
resolves to:
[development]> Rails.logger
=> #<ActiveSupport::Logger:0x000000010cef2010 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x000000010b9052c0 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x000000010cef1f98 @datetime_format=nil, @thread_key="activesupport_tagged_logging_tags:78900">, @logdev=#<Logger::LogDevice:0x000000010b905248 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @binmode=false, @mon_data=#<Monitor:0x000000010b9050b8>, @mon_data_owner_object_id=65580>>
We have the following aws
gems installed:
gem 'aws-sdk-athena', '~> 1.2'
gem 'aws-sdk-cloudwatch', require: false
gem 'aws-sdk-ec2', '~> 1'
gem 'aws-sdk-kinesis'
gem 'aws-sdk-lambda', '~> 1.41'
gem 'aws-sdk-rails', '~> 3.6'
gem 'aws-sdk-route53', '~> 1.9.0'
gem 'aws-sdk-s3', '~> 1'
gem 'aws-sdk-secretsmanager', '~> 1.21'
gem 'aws-sdk-ses', '~> 1.7.0'
Thanks for that. I see your ActiveSupport logger level is 0. I think maybe this is intended behavior? The SDK is sending all information out as :info
by default, and since your Rails logger level is 0, it will print out to STDOUT as info. Since you changed it to debug, it's sending it to the debug method, and your Rails logger sees that and prints it because it's configured to do so.
So what you would probably want is to keep the SDK default of :info and instead use config.logger.level = Logger::ERROR
or equivalent in your Rails environment.
@mullermp what if I want my Aws log_level
to be at :error
and my Rails log_level to be at :info
? Is that not possible to have them separated?
I think it would be a good addition because Aws logs at :info
can get very spammy for us so we only want to know when things are erroring.
What's happening is that the Rails logger is configured as the logger
option for the SDK, so the SDK is using it to log at the level configured (:info
). Then your Rails logger is configured with level 0 (or :debug
). Rails will log messages and print if the level is equal or higher to the configured level (documentation). The rails logger sees the :info
logs from the SDK, and it's >= 0, so it outputs.
If you set Aws log level to :error, and Rails to :info
, it will still print SDK logs because error is higher than info. What you might want to try is setting the Aws log level to :debug
, and set your Rails logger to :info
. That way you won't see Aws logging unless you change to debug logging, but you'll see your info logging in Rails. You could similarly set Aws logging to :info
the default and change your Rails logging to :warn
.
I hope this makes sense.
@mullermp that makes sense, I just pasted my development configuration levels but in production, we are using :info
for Rails.
The only question I have is that even if I set my Aws SDK log level below my Rails log level, wouldn't the logs still output because the log itself would still be :info
? Or do ALL logs from the SDK get set to what I set my Aws config at?
All logs from the SDK will be what you configure log level with in AWS config. Then your Rails logger will determine whether it should output or not based on its level configuration.
perfect, thank you! That's everything I need!