Class: Rack::XIDLogging

Inherits:
Object
  • Object
show all
Defined in:
lib/unicorn-cuba-base/rack/xid_logging.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, root_logger, header_name = 'XID', &block) ⇒ XIDLogging

Returns a new instance of XIDLogging.



3
4
5
6
7
# File 'lib/unicorn-cuba-base/rack/xid_logging.rb', line 3

def initialize(app, root_logger, header_name = 'XID', &block)
	@root_logger = root_logger
	@header_name = header_name
	@app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/unicorn-cuba-base/rack/xid_logging.rb', line 9

def call(env)
	begin
		xid = env["HTTP_#{@header_name.upcase.tr('-', '_')}"]
		if xid
			env['xid'] = {@header_name => xid}
			@root_logger.with_meta_context(xid: xid) do
				return @app.call(env)
			end
		else
			return @app.call(env)
		end
	ensure
	end
end