Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display halted callbacks in log for Application Controller #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/lograge/log_subscribers/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def extract_unpermitted_params
RequestStore.store[:lograge_unpermitted_params] = nil
{ unpermitted_params: unpermitted_params }
end

def extract_halted_callback
halted_callback = RequestStore.store[:lograge_halted_callback]
return {} unless halted_callback

RequestStore.store[:lograge_halted_callback] = nil
{ halted_callback: halted_callback }
end
end
end
end
3 changes: 2 additions & 1 deletion lib/lograge/log_subscribers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def extract_request(event, payload)
data.merge!(extract_runtimes(event, payload))
data.merge!(extract_location)
data.merge!(extract_unpermitted_params)
data.merge!(extract_halted_callback)
data.merge!(custom_options(event))
end

%i[initial_data extract_status extract_runtimes
extract_location extract_unpermitted_params].each do |method_name|
extract_location extract_unpermitted_params extract_halted_callback].each do |method_name|
define_method(method_name) { |*_arg| {} }
end

Expand Down
23 changes: 22 additions & 1 deletion spec/log_subscribers/action_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,28 @@
expect(log_output.string).to_not include('location=')
end

context 'with unpermitted_parameters' do
context 'with halted_callback' do
before do
RequestStore.store[:lograge_halted_callback] = 'user_authenticated'
end

it 'adds the halted_callback to the log line' do
subscriber.process_action(event)
expect(log_output.string).to include('halted_callback=user_authenticated')
end

it 'removes the thread local variable' do
subscriber.process_action(event)
expect(RequestStore.store[:lograge_halted_callback]).to be_nil
end
end

it 'does not include halted_callback by default' do
subscriber.process_action(event)
expect(log_output.string).to_not include('halted_callback=')
end

context 'with unpermitted_params' do
before do
RequestStore.store[:lograge_unpermitted_params] = %w[florb blarf]
end
Expand Down
Loading