Class: PG::Connection::GeneralLog::Middleware
- Inherits:
-
Object
- Object
- PG::Connection::GeneralLog::Middleware
- Defined in:
- lib/pg/connection/general_log/middleware.rb
Class Attribute Summary collapse
-
.backtrace ⇒ Object
Returns the value of attribute backtrace.
-
.enabled ⇒ Object
Returns the value of attribute enabled.
-
.path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #extract_request_id(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
11 12 13 14 15 16 17 18 |
# File 'lib/pg/connection/general_log/middleware.rb', line 11 def initialize(app, = {}) @app = app Middleware.enabled = [:enabled] Middleware.path = [:path] || '/tmp/general_log' Middleware.backtrace = [:backtrace] || false GeneralLog.prepend_module if Middleware.enabled end |
Class Attribute Details
.backtrace ⇒ Object
Returns the value of attribute backtrace.
8 9 10 |
# File 'lib/pg/connection/general_log/middleware.rb', line 8 def backtrace @backtrace end |
.enabled ⇒ Object
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/pg/connection/general_log/middleware.rb', line 8 def enabled @enabled end |
.path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/pg/connection/general_log/middleware.rb', line 8 def path @path end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 |
# 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 |