Skip to content

Commit 6f8f830

Browse files
authored
Fix Container Logging (#1919)
1 parent 4801b72 commit 6f8f830

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,5 +663,5 @@ storage/
663663
bin/*.rb
664664

665665
/config/credentials/development.key
666-
666+
/config/credentials/staging.key
667667
/config/credentials/production.key

config/defaults/settings.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,8 @@ default_locale: :en
913913

914914
# Configure the logging verbosity of the application.
915915
#
916-
# Valid values are: debug, info, warn, error, fatal
917-
log_level: 'warn'
916+
# Valid values are: :debug, :info, :warn, :error, :fatal
917+
log_level: :warn
918918

919919
# In containers, it is usually desired to log to stdout
920920
# instead of using log files (e.g. log/production.log).

config/environments/production.rb

+17-18
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,26 @@
5454
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
5555
config.force_ssl = ENV.key?("FORCE_SSL")
5656

57-
# Log to STDOUT by default
58-
config.logger = ActiveSupport::Logger.new($stdout)
59-
.tap { |logger| logger.formatter = Logger::Formatter.new }
60-
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
61-
62-
# config.logger = Logger.new($stdout) if Settings.log_to_stdout
63-
config.log_level = Settings.log_level ? Settings.log_level.downcase.to_sym : "error"
64-
65-
# Prepend all log lines with the following tags.
66-
config.log_tags = [:request_id]
57+
# Logging
58+
config.logger = if ENV["RAILS_LOG_TO_STDOUT"].present? || Settings.log_to_stdout
59+
# Log to STDOUT by default
60+
ActiveSupport::Logger.new($stdout)
61+
.tap { |logger| logger.formatter = Logger::Formatter.new }
62+
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
63+
else
64+
ActiveSupport::TaggedLogging.new(Logger.new("log/production.log"))
65+
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
66+
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
67+
end
6768

6869
# Info include generic and useful information about system operation, but avoids logging too much
6970
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
7071
# want to log everything, set the level to "debug".
71-
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
72+
# Obey settings.yml
73+
config.log_level = Settings.log_level
74+
75+
# Prepend all log lines with the following tags.
76+
config.log_tags = [:request_id]
7277

7378
# Use a different cache store in production.
7479
# config.cache_store = :mem_cache_store
@@ -77,7 +82,7 @@
7782
# config.active_job.queue_adapter = :resque
7883
# config.active_job.queue_name_prefix = "password_pusher_production"
7984

80-
config.action_mailer.perform_caching = false
85+
config.action_mailer.perform_caching = true
8186

8287
# Ignore bad email addresses and do not raise email delivery errors.
8388
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
@@ -135,12 +140,6 @@
135140
end
136141
end
137142

138-
if ENV["RAILS_LOG_TO_STDOUT"].present? || Settings.log_to_stdout
139-
logger = ActiveSupport::Logger.new($stdout)
140-
logger.formatter = config.log_formatter
141-
config.logger = ActiveSupport::TaggedLogging.new(logger)
142-
end
143-
144143
# If a user sets the allowed_hosts setting, we need to add the domain(s) to the list of allowed hosts
145144
if Settings.allowed_hosts.present?
146145
if Settings.allowed_hosts.is_a?(Array)

config/initializers/rack_attack.rb

-8
This file was deleted.

config/settings.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,8 @@ default_locale: :en
913913

914914
# Configure the logging verbosity of the application.
915915
#
916-
# Valid values are: debug, info, warn, error, fatal
917-
log_level: 'warn'
916+
# Valid values are: :debug, :info, :warn, :error, :fatal
917+
log_level: :warn
918918

919919
# In containers, it is usually desired to log to stdout
920920
# instead of using log files (e.g. log/production.log).

0 commit comments

Comments
 (0)