Class: LogStash::Api::RackApp::ApiLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/api/rack_app.rb

Constant Summary collapse

LOG_MESSAGE =
"API HTTP Request".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ ApiLogger

Returns a new instance of ApiLogger.



25
26
27
28
# File 'lib/logstash/api/rack_app.rb', line 25

def initialize(app, logger)
  @app = app
  @logger = logger
end

Instance Method Details

#call(env) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/logstash/api/rack_app.rb', line 30

def call(env)
  res = @app.call(env)
  status, headers, body = res

  if fatal_error?(status)
    @logger.error? && @logger.error(LOG_MESSAGE, RackApp.(status, env))
  else
    @logger.debug? && @logger.debug(LOG_MESSAGE, RackApp.(status, env))
  end

  res
end

#fatal_error?(status) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/logstash/api/rack_app.rb', line 43

def fatal_error?(status)
  status >= 500 && status < 600
end