Class: Lennarb::Middleware::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/lennarb/middleware/request_logger.rb

Overview

Request logger for the Lennarb framework Logs HTTP request details with color formatting

Examples:

Output:

GET /users/123 (30ms)
Status: 200 OK
Params: {"id"=>"123", "password"=>"[FILTERED]"}

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestLogger

Returns a new instance of RequestLogger.



12
13
14
# File 'lib/lennarb/middleware/request_logger.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

Process the request and log information

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array)

    Rack response [status, headers, body]



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lennarb/middleware/request_logger.rb', line 23

def call(env)
  request = Lennarb::Request.new(env)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

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

  duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time

  log_request(request, status, headers, duration)

  [status, headers, body]
end

#loggerObject

Get logger from application configuration



17
# File 'lib/lennarb/middleware/request_logger.rb', line 17

def logger = Lennarb::App.app.config.logger