lib/rack/ougai/log_requests.rb in rack-ougai-0.1.0 vs lib/rack/ougai/log_requests.rb in rack-ougai-0.2.0
- old
+ new
@@ -7,26 +7,35 @@
@app = app
@logger = logger
end
def call(env)
- status, headers, body = @app.call(env)
+ start_time = Time.now
+ status, headers, _body = @app.call(env)
ensure
logger = @logger || env[RACK_LOGGER]
- logger.info('HTTP Request', create_log(env, status, headers))
+ logger.info('http', create_log(start_time, env, status, headers))
end
private
- def create_log(env, status, header)
- {
- time: Time.now,
+ def create_log(start_time, env, status, _headers)
+ end_time = Time.now
+
+ ret = {
+ time: start_time,
+ usec: end_time.usec - start_time.usec,
remote_addr: env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"],
method: env[REQUEST_METHOD],
path: env[PATH_INFO],
query: env[QUERY_STRING],
status: status.to_i,
}
+
+ request_id = env['HTTP_X_REQUEST_ID']
+ ret[:request_id] = request_id unless request_id.nil?
+
+ ret
end
end
end
end