Sha256: a8629b061ab1af7835d25b885e7ea6575ef178623f73b063f575fa66deb06587

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 KB

Contents

module Climatic
  module Logger

    class Accumulator

      STACK_OPS = %i(debug info warn error fatal unknown).freeze

      attr_accessor :level

      def initialize
        @log_lines = [{op: :debug, args: ['Starting special temporary "accumulator" logger...']}]
      end

      def stack(op, *args)
        log_lines << {op: op, args: args}
      end

      def transfer_content_to(other_logger)
        debug "Transferring accumulated logs to logger '#{other_logger.inspect}'"
        if other_logger.nil?
          @log_lines = []
          return
        end
        log_lines.each do |log_line|
          other_logger.send log_line[:op], *log_line[:args]
        end
        @log_lines = []
      end

      def method_missing(method_name, *args)
        if STACK_OPS.include? method_name
          stack method_name, *args
        else
          super
        end
      end

      def respond_to_missing?(method_name, include_private = false)
        STACK_OPS.include?(method_name) || super
      end

      private

      attr_reader :log_lines

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
climatic-0.2.40 lib/climatic/logger/accumulator.rb
climatic-0.2.39 lib/climatic/logger/accumulator.rb
climatic-0.2.38 lib/climatic/logger/accumulator.rb
climatic-0.2.37 lib/climatic/logger/accumulator.rb
climatic-0.2.36 lib/climatic/logger/accumulator.rb
climatic-0.2.35 lib/climatic/logger/accumulator.rb
climatic-0.2.34 lib/climatic/logger/accumulator.rb
climatic-0.2.32 lib/climatic/logger/accumulator.rb
climatic-0.2.31 lib/climatic/logger/accumulator.rb
climatic-0.2.30 lib/climatic/logger/accumulator.rb
climatic-0.2.29 lib/climatic/logger/accumulator.rb
climatic-0.2.28 lib/climatic/logger/accumulator.rb
climatic-0.2.27 lib/climatic/logger/accumulator.rb
climatic-0.2.26 lib/climatic/logger/accumulator.rb