Class: SharkOnLambda::Middleware::LambdaLogger

Inherits:
Base
  • Object
show all
Defined in:
lib/shark_on_lambda/middleware/lambda_logger.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#call

Constructor Details

#initialize(app, logger: SharkOnLambda.logger) ⇒ LambdaLogger

Returns a new instance of LambdaLogger.



8
9
10
11
# File 'lib/shark_on_lambda/middleware/lambda_logger.rb', line 8

def initialize(app, logger: SharkOnLambda.logger)
  super(app)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/shark_on_lambda/middleware/lambda_logger.rb', line 6

def logger
  @logger
end

Instance Method Details

#call!(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shark_on_lambda/middleware/lambda_logger.rb', line 13

def call!(env)
  start_time = Time.now
  response = app.call(env)
  duration = duration_in_ms(start_time, Time.now)

  if logger.info?
    log_request(env: env, response: response, duration: duration)
  end

  response
end