From 9153f61ef8a8f8259d23ab28ae64d96bc9d31957 Mon Sep 17 00:00:00 2001 From: rhymes Date: Fri, 21 Feb 2020 19:56:39 +0100 Subject: [PATCH] Optionally log to stdout (#6230) --- config/database.yml | 3 +++ config/environments/development.rb | 9 +++++++-- docs/faqs.md | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/config/database.yml b/config/database.yml index d84d0337c..0698b14ae 100644 --- a/config/database.yml +++ b/config/database.yml @@ -24,10 +24,13 @@ default: &default checkout_timeout: 2 variables: statement_timeout: <%= ENV['STATEMENT_TIMEOUT'] || 2500 %> + development: <<: *default url: <%= ENV.fetch('DATABASE_URL', '') %> database: PracticalDeveloper_development + variables: + statement_timeout: <%= ENV['STATEMENT_TIMEOUT'] || 10_000 %> # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. diff --git a/config/environments/development.rb b/config/environments/development.rb index e68f2a40c..1a8a4ddcd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -96,6 +96,12 @@ Rails.application.configure do # Debug is the default log_level, but can be changed per environment. config.log_level = :debug + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + config.after_initialize do # See for other Bullet config options Bullet.enable = true @@ -108,8 +114,7 @@ Rails.application.configure do # acts-as-taggable-on has super weird eager loading problems: Bullet.add_whitelist(type: :n_plus_one_query, class_name: "ActsAsTaggableOn::Tagging", association: :tag) - DATA_UPDATE_CHECK_COMMANDS = %w[c console s server].freeze - if DATA_UPDATE_CHECK_COMMANDS.include?(ENV["COMMAND"]) + if %w[c console runner s server].include?(ENV["COMMAND"]) script_ids = DataUpdateScript.load_script_ids scripts_to_run = DataUpdateScript.where(id: script_ids).select(&:enqueued?) if scripts_to_run.any? diff --git a/docs/faqs.md b/docs/faqs.md index d7e0e981d..249de844b 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -30,3 +30,15 @@ sudo -u postgres createdb ec2-user The first command creates the user **ec2-user** and the second one creates the database for this user because every user needs its database. Even if the first command fails, run the second command to create the missing database. + +## How do I enable logging to standard output in development? + +By default Rails logs to `log.development.log`. + +If, instead, you wish to log to `STDOUT` you can add the variable: + +```yaml +RAILS_LOG_TO_STDOUT: true +``` + +to your own `config/application.yml` file.