Sha256: 00c22abcb72fb4dd830a20daeda1aaf698e42ea96194b79633b6dbca979668ae

Contents?: true

Size: 644 Bytes

Versions: 1

Compression:

Stored size: 644 Bytes

Contents

# frozen_string_literal: true

module FluentLoggerRails
  module TaggedLogging
    def self.new(logger, format: :hash)
      logger.formatter = if format == :hash
        HashFormatter.new
      elsif format == :pretty_json
        PrettyJsonFormatter.new
      elsif format == :json
        JsonFormatter.new
      else
        fail "Unrecognized log format: '#{format}'"
      end

      logger.extend(self)
    end

    delegate :add_tags, :remove_tags, :clear_tags!, to: :formatter

    def tagged(*tags)
      formatter.tagged(*tags) { yield self }
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent_logger_rails-0.1.0 lib/fluent_logger_rails/tagged_logging.rb