Sha256: e64956786c2bc5fbb44fcd7b5399224d802fb524278900fb2d3fa0bdebfb1c3c
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
module L2meter class Emitter attr_reader :configuration def initialize(configuration: Configuration.new) @configuration = configuration end def log(*args, **params) args = args.map { |key| [ key, true ] }.to_h params = args.merge(params) params = context.merge(params) if block_given? wrap params, &Proc.new else write params end end private def context configuration.get_context end def write(params) tokens = params.map do |key, value| key = configuration.key_formatter.call(key) next key if value == true value = configuration.value_formatter.call(value) [ key, value ] * ?= end tokens.sort! if configuration.sort? configuration.output.puts tokens.join(" ") end def wrap(params) time_at_start = Time.now write params.merge(at: :start) yield rescue => error status = { at: :exception, exception: error.class.to_s, message: error.message.strip } raise else status = { at: :finish } ensure elapsed = Time.now - time_at_start status.merge! elapsed: "%.4fs" % elapsed write params.merge(status) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
l2meter-0.0.1 | lib/l2meter/emitter.rb |