Sha256: 7edfeece12e75b9c71466c88ffab0a522c7d8c353ca14c3ee9bb21840425e0fc

Contents?: true

Size: 811 Bytes

Versions: 9

Compression:

Stored size: 811 Bytes

Contents

module LogStashLogger
  # Shamelessly copied from ActiveSupport::TaggedLogging
  module TaggedLogging
    def tagged(*tags)
      formatter.tagged(*tags) { yield self }
    end

    def flush
      formatter.clear_tags!
      super if defined?(super)
    end

    module Formatter
      def tagged(*tags)
        new_tags = push_tags(*tags)
        yield self
      ensure
        pop_tags(new_tags.size)
      end

      def push_tags(*tags)
        tags.flatten.reject{ |t| t.nil? || t.empty? }.tap do |new_tags|
          current_tags.concat new_tags
        end
      end

      def pop_tags(size = 1)
        current_tags.pop size
      end

      def clear_tags!
        current_tags.clear
      end

      def current_tags
        Thread.current[:logstash_logger_tags] ||= []
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
logstash-logger-p-0.26.1 lib/logstash-logger/tagged_logging.rb
logstash-logger-yajl-0.27.0 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.26.1 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.26.0 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.25.1 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.25.0 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.24.1 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.24.0 lib/logstash-logger/tagged_logging.rb
logstash-logger-0.23.0 lib/logstash-logger/tagged_logging.rb