Class: TaggedLogger

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

Overview

Allow custom tags to be captured

Instance Method Summary collapse

Constructor Details

#initialize(app, logger: Logger.new(STDOUT), tags: [], use_default_tags: true, tld_length: 1, include_log_severity: true) ⇒ TaggedLogger

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sensible_logging/middlewares/tagged_logger.rb', line 9

def initialize( # rubocop:disable Metrics/ParameterLists
  app,
  logger: Logger.new(STDOUT),
  tags: [],
  use_default_tags: true,
  tld_length: 1,
  include_log_severity: true
)
  @app = app

  logger = setup_severity_tag(logger) if include_log_severity

  @logger = ActiveSupport::TaggedLogging.new(logger)
  @tags = []
  @tags += default_tags(tld_length: tld_length) if use_default_tags
  @tags += tags
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
# File 'lib/sensible_logging/middlewares/tagged_logger.rb', line 27

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