From 84b7b71f0276f54a3d5c906c606fb9be337cef7d Mon Sep 17 00:00:00 2001 From: Quentin de Metz Date: Mon, 17 Oct 2022 11:59:20 +0200 Subject: [PATCH] call log_process_action to get the right status code (devise) --- lib/lograge/log_subscribers/action_controller.rb | 3 +++ spec/log_subscribers/action_controller_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/lograge/log_subscribers/action_controller.rb b/lib/lograge/log_subscribers/action_controller.rb index 5afde029..6d25994d 100644 --- a/lib/lograge/log_subscribers/action_controller.rb +++ b/lib/lograge/log_subscribers/action_controller.rb @@ -1,9 +1,12 @@ # frozen_string_literal: true +require 'action_controller' + module Lograge module LogSubscribers class ActionController < Base def process_action(event) + ::ActionController::Base.log_process_action(event.payload) process_main_event(event) end diff --git a/spec/log_subscribers/action_controller_spec.rb b/spec/log_subscribers/action_controller_spec.rb index f272fad5..34544890 100644 --- a/spec/log_subscribers/action_controller_spec.rb +++ b/spec/log_subscribers/action_controller_spec.rb @@ -364,6 +364,15 @@ end end + context 'with a status code that is set in log_process_action (devise)' do + it 'returns the correct status code' do + allow(::ActionController::Base).to receive(:log_process_action) { |payload| payload[:status] = 401 } + event.payload[:status] = nil + subscriber.process_action(event) + expect(log_output.string).to match(/status=401 /) + end + end + it "will fallback to ActiveSupport's logger if one isn't configured" do Lograge.formatter = Lograge::Formatters::KeyValue.new Lograge.logger = nil