Sha256: 9007dc447eea03157b95cc98d855b2e8f572126d02d46f1cf5aabd2df34499bb

Contents?: true

Size: 789 Bytes

Versions: 10

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true

require 'logstash-event'

module Sidekiq
  module Logging
    # Class that takes a log payload and format it to be Logstash-compatible.
    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
        begin
          custom_options&.call(json_data)
        rescue StandardError
          nil
        end
        event = LogStash::Event.new(json_data)

        "#{event.to_json}\n"
      end

      private

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sidekiq-logstash-3.2.1 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-3.2.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-3.1.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-3.0.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-2.0.3 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-2.0.2 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-2.0.1 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-1.2.1 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-2.0.0 lib/sidekiq/logging/logstash_formatter.rb
sidekiq-logstash-1.2.0 lib/sidekiq/logging/logstash_formatter.rb