Sha256: 4a681e2affa63ef507d8941ef1b83489fe3e6f05b6b47ed5dc5d26d02b4b082b

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'sidekiq/logstash/configuration'
require 'sidekiq/logstash/version'
require 'sidekiq/logging/logstash_formatter'
require 'sidekiq/logging/argument_filter'
require 'sidekiq/logstash_job_logger'

module Sidekiq
  # Main level module for Sidekiq::Logstash.
  # Provides integration between Sidekiq and Logstash by changing the way
  # Sidekiq jobs are logged.
  module Logstash
    def self.configuration
      @configuration ||= Configuration.new
    end

    def self.configure
      yield(configuration)
    end

    def self.setup(_opts = {})
      # Calls Sidekiq.configure_server to inject logics
      Sidekiq.configure_server do |config|
        if defined?(Sidekiq::ExceptionHandler::Logger)
          # Remove default Sidekiq error_handler that logs errors
          # NOTE: this only exists up until Sidekiq 6.4.x
          config.error_handlers.delete_if { |h| h.is_a?(Sidekiq::ExceptionHandler::Logger) }
        end

        # Add logstash support
        if config.respond_to?(:[]=)
          # Only available from Sidekiq 6.5
          config[:job_logger] = Sidekiq::LogstashJobLogger
        else
          # This is deprecated and will be removed in Sidekiq 7.0
          config.options[:job_logger] = Sidekiq::LogstashJobLogger
        end

        # Set custom formatter for Sidekiq logger
        config.logger.formatter = Sidekiq::Logging::LogstashFormatter.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-logstash-2.0.3 lib/sidekiq/logstash.rb