diff --git a/app/controllers/api/v1/authentication_controller.rb b/app/controllers/api/v1/authentication_controller.rb index 2e6b9da71..7d54f0c19 100644 --- a/app/controllers/api/v1/authentication_controller.rb +++ b/app/controllers/api/v1/authentication_controller.rb @@ -4,6 +4,7 @@ module Api module V1 class AuthenticationController < ::Api::V1::BaseController skip_before_action :authenticate_user! + around_action :log_everything def create skip_authorization @@ -25,6 +26,27 @@ def create def token_duration OstConfig.jwt_duration end + + def log_everything + log_headers + yield + ensure + log_response + end + + def log_headers + http_envs = {}.tap do |envs| + request.headers.each do |key, value| + envs[key] = value if key.downcase.starts_with?('http') + end + end + + logger.info "Received #{request.method.inspect} to #{request.url.inspect} from #{request.remote_ip.inspect}. Processing with headers #{http_envs.inspect} and params #{params.inspect}" + end + + def log_response + logger.info "Responding with #{response.status.inspect} => #{response.body.inspect}" + end end end end