From 5b45b6f80fcab22a878c01d226656c476d280c24 Mon Sep 17 00:00:00 2001 From: Tuomas Nylund Date: Mon, 17 Jul 2023 11:27:13 +0100 Subject: [PATCH 1/2] Use ActiveSupport::Logger instead of Ruby std Logger for the Rails application logger Rails libraries expect the `Rails.logger` instance to inherit from ActiveSupport::Logger. The standard library logger for example does not implement methods like `silence` which is used by some of the Rails internals. This change fixes the inheritance issue. Co-authored-by: laura.ghiorghisor@digital.cabinet-office.gov.uk --- lib/govuk_app_config/govuk_json_logging.rb | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/govuk_app_config/govuk_json_logging.rb b/lib/govuk_app_config/govuk_json_logging.rb index c1589cf..c52ecbd 100644 --- a/lib/govuk_app_config/govuk_json_logging.rb +++ b/lib/govuk_app_config/govuk_json_logging.rb @@ -8,24 +8,21 @@ def self.configure # indefinitely while troubleshooting. $stdout.sync = true - Rails.logger = Logger.new( - $stdout, - level: Rails.logger.level, - formatter: proc { |severity, datetime, _progname, msg| - hash = { - "@timestamp": datetime.utc.iso8601(3), - message: msg, - level: severity, - tags: %w[rails], - } + Rails.logger = ActiveSupport::Logger.new($stdout, level: Rails.logger.level) + Rails.logger.formatter = proc { |severity, datetime, _progname, msg| + hash = { + "@timestamp": datetime.utc.iso8601(3), + message: msg, + level: severity, + tags: %w[rails], + } - if defined?(GdsApi::GovukHeaders) && !GdsApi::GovukHeaders.headers[:govuk_request_id].nil? - hash[:govuk_request_id] = GdsApi::GovukHeaders.headers[:govuk_request_id] - end + if defined?(GdsApi::GovukHeaders) && !GdsApi::GovukHeaders.headers[:govuk_request_id].nil? + hash[:govuk_request_id] = GdsApi::GovukHeaders.headers[:govuk_request_id] + end - "#{hash.to_json}\n" - }, - ) + "#{hash.to_json}\n" + } LogStasher.add_custom_fields do |fields| # Mirrors Nginx request logging, e.g. GET /path/here HTTP/1.1 From cc9fdbd4e9cf79ddccbc5661ecdeaddea2f2fc8b Mon Sep 17 00:00:00 2001 From: Tuomas Nylund Date: Mon, 17 Jul 2023 11:34:08 +0100 Subject: [PATCH 2/2] Bump version --- CHANGELOG.md | 4 ++++ lib/govuk_app_config/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26a18fc..afe2bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 9.0.4 + +* Fix an issue with Rails.logger being not an instance of ActiveSupport::Logger. Rails expects Rails.logger to have methods that Ruby STD Logger does not provide. e.g. `silence()` ([#309](https://github.com/alphagov/govuk_app_config/pull/309)) + # 9.0.3 * When error is reported by Rails logger, the field is now logged as "error_message" in order to avoid overwriting the "message" field. diff --git a/lib/govuk_app_config/version.rb b/lib/govuk_app_config/version.rb index 9f74bed..c019709 100644 --- a/lib/govuk_app_config/version.rb +++ b/lib/govuk_app_config/version.rb @@ -1,3 +1,3 @@ module GovukAppConfig - VERSION = "9.0.3".freeze + VERSION = "9.0.4".freeze end