Sha256: f92f8a3586872d826b6c5cb6551a6e6be27026b09c07d57a9d70042a7aa8906c
Contents?: true
Size: 707 Bytes
Versions: 2
Compression:
Stored size: 707 Bytes
Contents
require "benchmark" module GlassOctopus module Middleware class CommonLogger FORMAT = "Processed message. topic=%s, partition=%d, key=%s, runtime=%fms".freeze def initialize(app, logger=nil, log_level=:info) @app = app @logger = logger @log_level = log_level end def call(ctx) log(ctx) { @app.call(ctx) } end private def log(ctx) logger = @logger || ctx.logger runtime = Benchmark.realtime { yield } runtime *= 1000 # Convert to milliseconds logger.send(@log_level, format(FORMAT, ctx.message.topic, ctx.message.partition, ctx.message.key, runtime)) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
glass_octopus-1.1.0 | lib/glass_octopus/middleware/common_logger.rb |
glass_octopus-1.0.0 | lib/glass_octopus/middleware/common_logger.rb |