class RabbitmqClient::JsonFormatter

Formatter for json log messages

Constants

TIME_FORMAT

Public Class Methods

new() click to toggle source
# File lib/rabbitmq_client/json_formatter.rb, line 9
def initialize
  @json = {}
  @msg = ''
end

Public Instance Methods

build_new_json(msg) click to toggle source
# File lib/rabbitmq_client/json_formatter.rb, line 23
def build_new_json(msg)
  @msg  = msg
  @json = @msg.is_a?(Hash) ? @msg : { message: @msg.strip }
  @json.merge(TagsFilter.tags || {})
end
call(severity, timestamp, progname, msg) click to toggle source
# File lib/rabbitmq_client/json_formatter.rb, line 14
def call(severity, timestamp, progname, msg)
  @json = build_new_json(msg)
  @json = @json.merge(progname: progname.to_s, level: severity,
                      timestamp: timestamp.strftime(TIME_FORMAT))
  @json = @json.reject { |_key, value| value.to_s.empty? }

  @json.to_json + "\n"
end