diff --git a/Gemfile b/Gemfile index 54d9a08c9..ef912858b 100644 --- a/Gemfile +++ b/Gemfile @@ -94,3 +94,7 @@ group :test do gem "vcr", "~> 6.2" gem "webmock", "~> 3.18" end + +group :production do + gem "rails_semantic_logger" +end diff --git a/Gemfile.lock b/Gemfile.lock index 329eb74f6..1c26a55d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -349,6 +349,10 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) + rails_semantic_logger (4.14.0) + rack + railties (>= 5.1) + semantic_logger (~> 4.13) railties (7.1.3.1) actionpack (= 7.1.3.1) activesupport (= 7.1.3.1) @@ -435,6 +439,8 @@ GEM rexml ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + semantic_logger (4.15.0) + concurrent-ruby (~> 1.0) sentry-rails (5.10.0) railties (>= 5.0) sentry-ruby (~> 5.10.0) @@ -580,6 +586,7 @@ DEPENDENCIES rack-attack rails (~> 7.1.3) rails-erd + rails_semantic_logger rladr (~> 1.2) rspec rspec-rails diff --git a/config/environments/production.rb b/config/environments/production.rb index b08fdffd0..9cf3348ea 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,4 +96,9 @@ config.action_mailer.notify_settings = { api_key: ENV.fetch("GOVUK_NOTIFY_API_KEY"), } + + config.log_level = :info # Or :warn, or :error + config.log_format = :json # For parsing in Logit + config.rails_semantic_logger.add_file_appender = false # Don't log to file + config.active_record.logger = nil # Don't log SQL end diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb index 45b34e2b7..f7807c7ee 100644 --- a/config/initializers/okcomputer.rb +++ b/config/initializers/okcomputer.rb @@ -1,7 +1,6 @@ require_relative "../../lib/ok_computer_checks/zendesk_check" require_relative "../../lib/ok_computer_checks/notify_check" -OkComputer.logger = Rails.logger OkComputer.mount_at = "health" OkComputer::Registry.register "postgresql", OkComputer::ActiveRecordCheck.new diff --git a/config/initializers/semantic_logger.rb b/config/initializers/semantic_logger.rb new file mode 100644 index 000000000..2a1c2785d --- /dev/null +++ b/config/initializers/semantic_logger.rb @@ -0,0 +1,10 @@ +return unless defined?(SemanticLogger) + +Rails.application.configure do + config.semantic_logger.application = "" # This is added by logstash from its tags + config.log_tags = [:request_id] # Prepend all log lines with the following tags +end + +SemanticLogger.add_appender(io: $stdout, level: Rails.application.config.log_level, +formatter: Rails.application.config.log_format) +Rails.application.config.logger.info('Application logging to STDOUT')