class PG::Connection::GeneralLog::Middleware
Attributes
backtrace[RW]
enabled[RW]
path[RW]
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/pg/connection/general_log/middleware.rb, line 11 def initialize(app, options = {}) @app = app Middleware.enabled = options[:enabled] Middleware.path = options[:path] || '/tmp/general_log' Middleware.backtrace = options[:backtrace] || false GeneralLog.prepend_module if Middleware.enabled end
Public Instance Methods
call(env)
click to toggle source
# File lib/pg/connection/general_log/middleware.rb, line 20 def call(env) if Middleware.enabled request = Rack::Request.new(env) request_id = extract_request_id(env) Thread.current[:request_id] = request_id end @app.call(env) ensure if Middleware.enabled GeneralLog.general_log_with_request_id(request_id)&.writefile(request) GeneralLog.delete_general_log(request_id) Thread.current[:request_id] = nil end end
extract_request_id(env)
click to toggle source
# File lib/pg/connection/general_log/middleware.rb, line 35 def extract_request_id(env) env['action_dispatch.request_id'] || env['HTTP_X_REQUEST_ID'] || SecureRandom.hex(16) end