Sha256: fa48e8e8037e8cfc27a3f783e959d7236ac39f2b8f542f6862444e4ddaeb1cb2

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

require 'logger'
require 'logstash-event'

module Kenny
  module Formatters
    ##
    # Formats messages as LogStash::Event
    # the 'type' field can be used for ElasticSearch
    # The 'type' could be set through the Logger's progname,
    # which takes the highest precedence.
    # If logger.progname.nil?, it will take the 'type' within the hash.
    # If the 'type' within the Hash is also nil,
    # then you can set the type through FileBeat's config
    class LogStashFormatter < ::Logger::Formatter
      def call(severity, time, progname, msg)
        msg = { 'message' => msg.is_a?(String) ? msg : msg.inspect } unless msg.is_a?(Hash)
        msg['severity'] = severity if severity
        msg['type'] = progname if progname

        event = LogStash::Event.new(msg)

        "%s\n" % event.to_json
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kenny-0.1.5 lib/kenny/formatters/log_stash_formatter.rb