diff --git a/Gemfile b/Gemfile index f254f2551f..69d6650249 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,9 @@ gem 'cancancan', '~> 2.0' group :production do # Use a postgres database in production. gem 'pg', '~> 0.18' + + # For a better logging library in production + gem "lograge" end # Ruby linting. diff --git a/Gemfile.lock b/Gemfile.lock index 4fa74d532f..89ccfcddd3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -155,6 +155,11 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) + lograge (0.11.2) + actionpack (>= 4) + activesupport (>= 4) + railties (>= 4) + request_store (~> 1.0) loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -250,6 +255,8 @@ GEM redcarpet (3.4.0) remote_syslog_logger (1.0.4) syslog_protocol + request_store (1.4.1) + rack (>= 1.4) rolify (5.2.0) rspec-core (3.8.2) rspec-support (~> 3.8.0) @@ -357,6 +364,7 @@ DEPENDENCIES jbuilder (~> 2.5) jquery-rails (~> 4.3.3) listen (~> 3.0.5) + lograge mini_racer net-ldap omniauth diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3667984047..1fea221338 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,6 +44,12 @@ class ApplicationController < ActionController::Base MEETING_NAME_LIMIT = 90 USER_NAME_LIMIT = 32 + # Include user domain in lograge logs + def append_info_to_payload(payload) + super + payload[:host] = @user_domain + end + # Show an information page when migration fails and there is a version error. def migration_error? render :migration_error unless ENV["DB_MIGRATE_FAILED"].blank? diff --git a/config/environments/production.rb b/config/environments/production.rb index eed2b5da59..4b050c6766 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -94,12 +94,20 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + # Use Lograge for logging + config.lograge.enabled = true - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + config.lograge.ignore_actions = ["HealthCheck::HealthCheckController#index"] + + config.lograge.custom_options = lambda do |event| + # capture some specific timing values you are interested in + { host: event.payload[:host] } + end + + config.log_formatter = proc do |severity, _time, _progname, msg| + "#{severity}: #{msg} \n" + end + config.log_level = :info if ENV["RAILS_LOG_TO_STDOUT"] == "true" logger = ActiveSupport::Logger.new(STDOUT) @@ -108,8 +116,10 @@ elsif ENV["RAILS_LOG_REMOTE_NAME"] && ENV["RAILS_LOG_REMOTE_PORT"] require 'remote_syslog_logger' logger_program = ENV["RAILS_LOG_REMOTE_TAG"] || "greenlight-#{ENV['RAILS_ENV']}" - config.logger = RemoteSyslogLogger.new(ENV["RAILS_LOG_REMOTE_NAME"], + logger = RemoteSyslogLogger.new(ENV["RAILS_LOG_REMOTE_NAME"], ENV["RAILS_LOG_REMOTE_PORT"], program: logger_program) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations.