Skip to content

Commit

Permalink
Log headers in auth api controller
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Nov 15, 2023
1 parent 32422df commit bdbb12b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/controllers/api/v1/authentication_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit bdbb12b

Please sign in to comment.