Class: TaggedLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/sensible_logging/middlewares/tagged_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = Logger.new(STDOUT), tags = [], tld_length = 1) ⇒ TaggedLogger



4
5
6
7
8
9
10
11
12
# File 'lib/sensible_logging/middlewares/tagged_logger.rb', line 4

def initialize(app, logger = Logger.new(STDOUT), tags = [], tld_length = 1)
  @app = app
  @logger = ActiveSupport::TaggedLogging.new(logger)

  @tags = tags
  @tags = default_tags if tags.empty?

  @tld_length = tld_length
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
# File 'lib/sensible_logging/middlewares/tagged_logger.rb', line 14

def call(env)
  @logger.tagged(*generate_tags(env)) do |logger|
    env['logger'] = logger
    @app.call(env)
  end
end

#default_tagsObject



21
22
23
24
25
# File 'lib/sensible_logging/middlewares/tagged_logger.rb', line 21

def default_tags
  [lambda { |req|
    [subdomain(req), ENV['RACK_ENV'], req.env['request_id']]
  }]
end