Class: Rails::Rack::Logger

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/rails/rack/logger.rb

Overview

Sets log tags, logs the request, calls the app, and flushes the logs.

Log tags (taggers) can be an Array containing: methods that the request object responds to, objects that respond to to_s or Proc objects that accept an instance of the request object.

Instance Method Summary collapse

Constructor Details

#initialize(app, taggers = nil) ⇒ Logger

Returns a new instance of Logger.



15
16
17
18
# File 'lib/rails/rack/logger.rb', line 15

def initialize(app, taggers = nil)
  @app          = app
  @taggers      = taggers || []
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails/rack/logger.rb', line 20

def call(env)
  request = ActionDispatch::Request.new(env)

  env["rails.rack_logger_tag_count"] = if logger.respond_to?(:push_tags)
    logger.push_tags(*compute_tags(request)).size
  else
    0
  end

  call_app(request, env)
end