Class: Rack::JsonLogFormatter
- Inherits:
-
Object
- Object
- Rack::JsonLogFormatter
- Defined in:
- lib/rack/json_common_logger.rb
Overview
Formats request log from rack env to json
Instance Method Summary collapse
-
#initialize(env, headers, status, began_at) ⇒ JsonLogFormatter
constructor
A new instance of JsonLogFormatter.
- #message ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(env, headers, status, began_at) ⇒ JsonLogFormatter
Returns a new instance of JsonLogFormatter.
15 16 17 18 19 20 |
# File 'lib/rack/json_common_logger.rb', line 15 def initialize(env, headers, status, began_at) @env = env @began_at = began_at @status = status @headers = headers end |
Instance Method Details
#message ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/json_common_logger.rb', line 26 def now = Time.now.utc { timestamp: now.strftime('%Y-%m-%dT%H:%M:%SZ'), method: env[REQUEST_METHOD], remote_address: remote_address, location: location, params: (env['rack.request.form_hash'] || {}), query_string: query_string, status: status.to_s[0..3], length: extract_content_length, duration: (now - began_at) } end |
#to_json ⇒ Object
22 23 24 |
# File 'lib/rack/json_common_logger.rb', line 22 def to_json "#{.to_json}\n" end |