Sha256: 8a0957dad4e7a6135ee5c09fb6a58d1fa68385219eda092dcacc7f7b03f111d0

Contents?: true

Size: 768 Bytes

Versions: 1

Compression:

Stored size: 768 Bytes

Contents

require "json"
require "time"

module Log4r
  module Logstash
    class JsonFormatter
      def self.format(logevent, index,
                     data_field_name = "data", level_field_name = "level",
                     additional_fields = {})
        data = {}
        data["type"] = "#{logevent.class}"
        data["index"] = "#{index}"
        data["timestamp"] = Time.now.getutc.iso8601
        data[level_field_name] = LNAMES[logevent.level]
        data[data_field_name] = logevent.data
        data.merge! eval_map_proc_values(additional_fields)
        data.to_json
      end

      def self.eval_map_proc_values(map)
        map.each do |key, value|
          map[key] = value.call if value.class == Proc
        end
        map
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
log4r-logstash-0.1.0 lib/log4r/logstash/formatter/json_formatter.rb