Sha256: 2d82d0920cbcf6cfa0d9c81ffe3faf85c003c3832516f49922839ed96472fcf7

Contents?: true

Size: 620 Bytes

Versions: 2

Compression:

Stored size: 620 Bytes

Contents

require 'logstash-event'

module Sidekiq
  module Logging
    class LogstashFormatter
      def call(severity, time, progname, data)
        json_data = { severity: severity }

        if data.is_a? Hash
          json_data.merge!(data)
        else
          json_data[:message] = data
        end

        # Merge custom_options to provide customization
        custom_options.call(json_data) if custom_options rescue nil
        event = LogStash::Event.new(json_data)

        "#{event.to_json}\n"
      end

      def custom_options
        Sidekiq::Logstash.configuration.custom_options
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-logstash-1.1.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-1.0.1 lib/sidekiq/logging/logstash_formatter.rb