Sha256: cab5911a3c533df250961df997f205d00062455f16d6a057f2f86e93bde392f3
Contents?: true
Size: 995 Bytes
Versions: 1
Compression:
Stored size: 995 Bytes
Contents
# frozen_string_literal: true require 'logger' module MrLogaLoga # == Description # # A proxy that attaches contextual information to the underlying logger when called. # # @api private class LoggerProxy def initialize(logger, context_proc) @logger = logger @context_proc = context_proc end def add(severity, message = nil, **context, &block) severity ||= UNKNOWN return true unless @logger.log?(severity) context = @context_proc.call.merge(context) @logger.add(severity, message, **context, &block) end alias log add %i[debug info warn error fatal unknown].each do |symbol| define_method(symbol) do |message = nil, **context, &block| severity = Object.const_get("Logger::Severity::#{symbol.to_s.upcase}") return true unless @logger.log?(severity) context = @context_proc.call.merge(context) @logger.public_send(symbol, message, **context, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mr_loga_loga-0.1.0 | lib/mr_loga_loga/logger_proxy.rb |