Sha256: e792ad585096dcea2bf8625daac47880d518c6414d6ae32eff55b26751c78f2c

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'json'
require 'English'

module RabbitmqClient
  # Formatter for text log messages
  class TextFormatter < ::Logger::Formatter
    def initialize
      @datetime_format = nil
      @severity_text = nil
      @tags = nil
      super
    end

    def call(severity, time, progname, msg)
      create_instance_vars(severity)
      format(Format,
             @severity_text[0],
             format_datetime(time),
             $PID,
             @severity_text,
             progname,
             "#{@tags}#{msg2str(msg)}")
    end

    private

    def create_instance_vars(severity)
      @severity_text = if severity.is_a?(Integer)
                         Logger::Severity.constants(false).select do |level|
                           Logger::Severity.const_get(level) == severity
                         end.first.to_s
                       else
                         severity
                       end
      @tags = (TagsFilter.tags || {}).collect do |key, val|
        "[#{key}: #{val}] "
      end.join
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rabbitmq_client-0.0.3 lib/rabbitmq_client/text_formatter.rb
rabbitmq_client-0.0.2 lib/rabbitmq_client/text_formatter.rb
rabbitmq_client-0.0.1 lib/rabbitmq_client/text_formatter.rb