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

Control log level with RAILS_LOG_LEVEL in production #47143

Merged
merged 3 commits into from Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -67,9 +67,10 @@ Rails.application.configure do
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
config.log_level = :info
# Info include generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). Use "debug"
# for everything.
config.log_level = ENV.fetch("RAILS_LOG_LEVEL") { "info" }

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down
9 changes: 9 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -1787,6 +1787,15 @@ def index
assert_equal Logger::INFO, Rails.logger.level
end

test "config.log_level can be overwritten by ENV['RAILS_LOG_LEVEL'] in production" do
restore_default_config

switch_env "RAILS_LOG_LEVEL", "debug" do
app "production"
assert_equal Logger::DEBUG, Rails.logger.level
end
end

test "config.log_level with custom logger" do
make_basic_app do |application|
application.config.logger = Logger.new(STDOUT)
Expand Down