Class: TimeBandits::Rack::Logger

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(app, taggers = nil) ⇒ Logger

Returns a new instance of Logger.



11
12
13
14
15
16
# File 'lib/time_bandits/rack/logger.rb', line 11

def initialize(app, taggers = nil)
  @app          = app
  @taggers      = taggers || Rails.application.config.log_tags || []
  @instrumenter = ActiveSupport::Notifications.instrumenter
  @use_to_default_s = Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("7.1.0")
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/time_bandits/rack/logger.rb', line 18

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

  if logger.respond_to?(:tagged) && !@taggers.empty?
    logger.tagged(compute_tags(request)) { call_app(request, env) }
  else
    call_app(request, env)
  end
end