Skip to content

Commit

Permalink
Remove Monkeypatching
Browse files Browse the repository at this point in the history
A monkeypatch in RailsExt::ActionDispatch existed to convert errors to pretty JSON. Now that we have set the default logger to log in JSON the transformed error message becomes a stringified JSON and not the best for error viewing. By removing the monkeypatch it should logs error nicely via logger we set.

Co-authored-by: Neamah Al-Selwi <neamah.alselwi@digital.cabinet-office.gov.uk>
Co-authored-by: Tuomas Nylund <tuomas.nylund@digital.cabinet-office.gov.uk>
  • Loading branch information
3 people committed Jul 5, 2023
1 parent e13795b commit 5b80c3c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 103 deletions.
5 changes: 1 addition & 4 deletions lib/govuk_app_config/govuk_json_logging.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require "json"
require "logstasher"
require "action_controller"
require_relative "rails_ext/action_dispatch/debug_exceptions"

module GovukJsonLogging
def self.configure
# We also disable buffering, so that logs aren't lost on crash or delayed
# We disable buffering, so that logs aren't lost on crash or delayed
# indefinitely while troubleshooting.
$stdout.sync = true

Expand Down Expand Up @@ -68,7 +67,5 @@ def self.configure
# the responses it gets, so direct this to the logstasher logger.
GdsApi::Base.default_options[:logger] = Rails.application.config.logstasher.logger
end

RailsExt::ActionDispatch.monkey_patch_log_error if RailsExt::ActionDispatch.should_monkey_patch_log_error?
end
end
49 changes: 0 additions & 49 deletions lib/govuk_app_config/rails_ext/action_dispatch/debug_exceptions.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/lib/govuk_json_logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def app
error_log_json_msg = error_log_json["message"]
expect(error_log_json_msg).to include("StandardError")
expect(error_log_json_msg).to include("default exception")
expect(error_log_json_msg).to match(/from.*:[0-9]+:in.*/)
expect(error_log_json_msg).to match(/[a-zA-Z]+.*:[0-9]+:in.*/)
end

it "logs errors thrown by the application with no govuk_request_id" do
Expand All @@ -118,7 +118,7 @@ def app
error_log_json_msg = error_log_json["message"]
expect(error_log_json_msg).to include("StandardError")
expect(error_log_json_msg).to include("default exception")
expect(error_log_json_msg).to match(/from.*:[0-9]+:in.*/)
expect(error_log_json_msg).to match(/[a-zA-Z].*:[0-9]+:in.*/)
end

it "logs to stdout in JSON format with govuk_request_id" do
Expand Down
48 changes: 0 additions & 48 deletions spec/lib/rails_ext/action_dispatch/debug_exceptions_spec.rb

This file was deleted.

0 comments on commit 5b80c3c

Please sign in to comment.