Sha256: 2b68ea61d173b19ff1a5e9c5f7d568ecca276b6a144b9aa4ea5ba1a3b9c32567

Contents?: true

Size: 632 Bytes

Versions: 2

Compression:

Stored size: 632 Bytes

Contents

require 'logstash-event'

module Sidekiq
  module Logging
    class LogstashFormatter
      def call(severity, time, progname, data)
        if data.is_a? Hash
          json_data = data
        else
          json_data = {
              severity: severity,
              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.0.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-0.3.0 lib/sidekiq/logging/logstash_formatter.rb