Sha256: ea9a327d4209c0e8bf3b8245f0212f3a284e1b36e44f5f6e42a27fba03b8eb96

Contents?: true

Size: 961 Bytes

Versions: 22

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module BBK
  module App
    class ProxyLogger

      attr_reader :tags, :logger

      def initialize(logger, tags:)
        @logger = logger
        @tagged = @logger.respond_to?(:tagged)
        @tags = [tags].flatten
      end

      def add_tags(*tags)
        @tags += tags.flatten
        @tags = @tags.uniq
      end

      def method_missing(method, *args, &block)
        super unless logger.respond_to?(method)

        if @tagged
          current_tags = tags - logger.formatter.current_tags
          logger.tagged(current_tags) { logger.send(method, *args, &block) }
        else
          logger.send(method, *args, &block)
        end
      end

      def respond_to?(*args)
        logger.send(:respond_to?, *args) || super
      end

      def respond_to_missing?(method_name, include_private = false)
        logger.send(:respond_to_missing?, method_name, include_private) || super
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bbk-app-1.0.0.72917 lib/bbk/app/proxy_logger.rb
bbk-app-1.0.0.72899 lib/bbk/app/proxy_logger.rb