Merge pull request #2388 from tchak/fix-lograge

Some improvements to lograge
This commit is contained in:
Paul Chavard 2018-08-13 17:03:58 +00:00 committed by GitHub
commit a3757758d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 10 deletions

View file

@ -101,8 +101,6 @@ class ApplicationController < ActionController::Base
super
user = logged_user
payload[:xhr] = !!request.xhr?
payload.merge!({
user_agent: request.user_agent,
user_id: user&.id,

View file

@ -6,6 +6,7 @@ Rails.application.configure do
# injected by ansible.
if !config.lograge.custom_options
config.lograge.custom_options = lambda do |event|
exception_object = event.payload[:exception_object]
{
type: 'tps',
user_id: event.payload[:user_id],
@ -14,13 +15,14 @@ Rails.application.configure do
user_agent: event.payload[:user_agent],
browser: event.payload[:browser],
browser_version: event.payload[:browser_version],
platform: event.payload[:platform]
platform: event.payload[:platform],
backtrace: exception_object ? exception_object.backtrace.join("\n") : nil
}.compact
end
config.lograge.custom_payload do |controller|
{
xhr: !!controller.request.xhr?
xhr: !!controller&.request&.xhr?
}
end
end

View file

@ -42,8 +42,7 @@ describe ApplicationController, type: :controller do
end
expect(payload).to eq({
user_agent: 'Rails Testing',
user_roles: 'Guest',
xhr: false
user_roles: 'Guest'
})
end
end
@ -64,8 +63,7 @@ describe ApplicationController, type: :controller do
user_agent: 'Rails Testing',
user_id: current_user.id,
user_email: current_user.email,
user_roles: 'User',
xhr: false
user_roles: 'User'
})
end
end
@ -89,8 +87,7 @@ describe ApplicationController, type: :controller do
user_agent: 'Rails Testing',
user_id: current_user.id,
user_email: current_user.email,
user_roles: 'User, Gestionnaire, Administrateur, Administration',
xhr: false
user_roles: 'User, Gestionnaire, Administrateur, Administration'
})
end
end