diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-28 08:30:26 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-28 08:30:26 +0000 |
commit | 190fae5f0cef11d68c7385be0c4013931796f958 (patch) | |
tree | cce10831d4b6b68b0b85787360e81e1a2cb27b8c | |
parent | 3f1b7b88c8d4f19a10920ad1629fc440af584d08 (diff) | |
parent | 96c4a15eae9b93a2bfb512309e860da50d2e2636 (diff) | |
download | gitlab-ce-190fae5f0cef11d68c7385be0c4013931796f958.tar.gz |
Merge branch 'sh-augment-lograge-output' into 'master'
Add remote IP, user ID and username to JSON lograge output
See merge request !13147
-rw-r--r-- | app/controllers/application_controller.rb | 10 | ||||
-rw-r--r-- | config/initializers/lograge.rb | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 43462b13903..d14b1dbecf6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -70,6 +70,16 @@ class ApplicationController < ActionController::Base protected + def append_info_to_payload(payload) + super + payload[:remote_ip] = request.remote_ip + + if current_user.present? + payload[:user_id] = current_user.id + payload[:username] = current_user.username + end + end + # This filter handles both private tokens and personal access tokens def authenticate_user_from_private_token! token = params[:private_token].presence || request.headers['PRIVATE-TOKEN'].presence diff --git a/config/initializers/lograge.rb b/config/initializers/lograge.rb index 039b4c87b0d..21fe8d72459 100644 --- a/config/initializers/lograge.rb +++ b/config/initializers/lograge.rb @@ -14,7 +14,10 @@ unless Sidekiq.server? config.lograge.custom_options = lambda do |event| { time: event.time.utc.iso8601(3), - params: event.payload[:params].except(*%w(controller action format)) + params: event.payload[:params].except(*%w(controller action format)), + remote_ip: event.payload[:remote_ip], + user_id: event.payload[:user_id], + username: event.payload[:username] } end end |