Class: Rack::TrafficLogger::Formatter::JSON

Inherits:
Rack::TrafficLogger::Formatter show all
Defined in:
lib/rack/traffic_logger/formatter/json.rb

Instance Method Summary collapse

Methods inherited from Rack::TrafficLogger::Formatter

#format

Constructor Details

#initialize(pretty_print: false) ⇒ JSON

Returns a new instance of JSON.



8
9
10
11
12
13
# File 'lib/rack/traffic_logger/formatter/json.rb', line 8

def initialize(pretty_print: false)
  formatter = pretty_print ?
      -> hash { ::JSON.pretty_generate(hash) << "\n" } :
      -> hash { ::JSON.generate(hash) << "\n" }
  define_singleton_method :format, formatter
end