From 6404aa9aa9bb0803af420c1c5f263d6a2fe600cc Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 29 Mar 2021 02:27:59 -0500 Subject: [PATCH] Log to stdout in development and production. Always log to stdout instead of logging to files in `log/{development,production}.log`. For development, logging to files wasn't really useful, and could generate multi-gigabyte log files if you weren't paying attention. For production, most systems these days (such as Docker and Systemd) prefer that you write your logs to stdout so they can manage them. Fixes the Docker image writing logs inside the container, which never got rotated and could fill up the container. --- config/environments/development.rb | 4 ++++ config/environments/production.rb | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 0dc1d03c6..00e3866be 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -64,6 +64,10 @@ Rails.application.configure do # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + BetterErrors::Middleware.allow_ip!(IPAddr.new("0.0.0.0/0")) BetterErrors::Middleware.allow_ip!(IPAddr.new("::/0")) diff --git a/config/environments/production.rb b/config/environments/production.rb index 21706aae9..d25c0bb32 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -76,11 +76,9 @@ Rails.application.configure do # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false