class ApplicationController < ActionController::Base
around_action :log_request
private
def log_request
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
ensure
duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started) * 1000).round(1)
Rails.logger.info({
msg: 'request',
method: request.request_method,
path: request.fullpath,
status: response.status,
duration_ms: duration_ms,
request_id: request.request_id,
member_id: current_member&.id
}.to_json)
end
end
Production debugging is about logs that are searchable. Emit JSON with consistent keys (requestid, memberid, duration). Even if you later add Lograge, this structure maps cleanly.