Skip to content

Instantly share code, notes, and snippets.

@kinsomicrote
Created January 6, 2024 08:38
Show Gist options
  • Save kinsomicrote/dcf8cb1fa654b16555302b451fd2638e to your computer and use it in GitHub Desktop.
Save kinsomicrote/dcf8cb1fa654b16555302b451fd2638e to your computer and use it in GitHub Desktop.
rails http header
before_action :log_request
def log_request
Rails.logger.info "Request: #{request.method} #{request.fullpath}"
http_envs = {}.tap do |envs|
request.headers.each do |key, value|
envs[key] = value if key.downcase.starts_with?('http')
end
end
logger.info <<-LOG.squish
Received #{request.method.inspect}
to #{request.url.inspect}
from #{request.remote_ip.inspect}.
Processing
with headers #{http_envs.inspect}
and params #{params.inspect}"
LOG
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment