Class: LoggerWare::Rack

Inherits:
Object
  • Object
show all
Includes:
Collector
Defined in:
lib/logger_ware/rack.rb

Constant Summary

Constants included from Collector

Collector::COLLECT_PARAMS, Collector::FILTER_PARAMS, Collector::PARAM_FILTERS

Constants included from Filter

Filter::REPLACE_WITH

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Collector

#_collect, #collect

Methods included from Filter

#filter, #filter?, #match?

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



23
24
25
# File 'lib/logger_ware/rack.rb', line 23

def initialize(app)
  @app = app
end

Class Attribute Details

.collect_paramsObject

Returns the value of attribute collect_params.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def collect_params
  @collect_params
end

.error_handlerObject

Returns the value of attribute error_handler.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def error_handler
  @error_handler
end

.filter_paramsObject

Returns the value of attribute filter_params.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def filter_params
  @filter_params
end

.filtersObject

Returns the value of attribute filters.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def filters
  @filters
end

.handlerObject

Returns the value of attribute handler.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def handler
  @handler
end

.replace_withObject

Returns the value of attribute replace_with.



16
17
18
# File 'lib/logger_ware/rack.rb', line 16

def replace_with
  @replace_with
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/logger_ware/rack.rb', line 27

def call(env)
  started_at = Time.now.utc

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

  handler[{status: status, headers: headers, response: response, started_at: started_at, duration: duration(started_at), data: data(env)}]
  [status, headers, response]

rescue => exception

  error_handler[{exception: exception, started_at: started_at, duration: duration(started_at), data: data(env)}]
  raise exception
end

#data(env) ⇒ Object



41
42
43
# File 'lib/logger_ware/rack.rb', line 41

def data(env)
  collect(env, collect_params, filter_params, filters, replace_with)
end

#duration(started_at) ⇒ Object



45
46
47
# File 'lib/logger_ware/rack.rb', line 45

def duration(started_at)
  Time.now.utc - started_at
end