From bdbb12bd62c3722203c9a2232fc26340edab4a2d Mon Sep 17 00:00:00 2001 From: moveson Date: Wed, 15 Nov 2023 07:15:38 -0700 Subject: [PATCH] Log headers in auth api controller --- .../api/v1/authentication_controller.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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