Skip to content

Commit

Permalink
Merge pull request #615 from IU-Libraries-Joint-Development/essi-1948…
Browse files Browse the repository at this point in the history
…_log_headers

Adding a global controller action to log request details
  • Loading branch information
randalldfloyd authored Apr 16, 2024
2 parents f8e8570 + a6a2438 commit e9c8c54
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ class ApplicationController < ActionController::Base
with_themed_layout '1_column'
protect_from_forgery with: :exception

around_action :global_request_logging

before_action do
if defined?(Rack::MiniProfiler) && current_user && current_user.admin?
Rack::MiniProfiler.authorize_request
end
end

rescue_from ActionController::UnknownFormat, with: :rescue_404

def global_request_logging
logger.info "ACCESS: #{request.remote_ip}, #{request.method} #{request.url}, #{request.headers['HTTP_USER_AGENT']}"
begin
yield
ensure
logger.info "response_status: #{response.status}"
end
end

def rescue_404
render file: Rails.public_path.join('404.html'), status: :not_found, layout: false
end
Expand Down

0 comments on commit e9c8c54

Please sign in to comment.