Sha256: 9383e567aee8496cffd76f897bd3bd625bf378f19cf246ef5bfa818cc5c56527
Contents?: true
Size: 855 Bytes
Versions: 16
Compression:
Stored size: 855 Bytes
Contents
require 'benchmark' require 'securerandom' require 'logger' module Attune class JsonLogger < Faraday::Middleware def initialize app, logger=nil super(app) @logger = logger || Logger.new(STDERR) end def call(env) time = (Time.now.to_f * 1000).to_i response = nil elapsed_time = Benchmark.realtime do response = @app.call(env) end log( ref: nil, v: 1, protocol: env[:url].scheme, host: env[:url].host, path: env[:url].path, t: time, r_id: SecureRandom.uuid, status: response.status, ua: env[:request_headers]['User-Agent'], method: env[:method], perf: { total: elapsed_time * 1000 } ) response end def log(data) @logger.info JSON.dump(data) end end end
Version data entries
16 entries across 16 versions & 1 rubygems