Sha256: f221da7950ee4a5a0fc9e85936dfa14408d2e864acc2765d0a2ab9811f289dde

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

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

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|
        require 'sidekiq/logstash_job_logger'

        # Remove default, noisy error handler,
        # unless LogStash.configuration.keep_default_error_handler is set to true
        unless configuration.keep_default_error_handler
          config.error_handlers.delete(Sidekiq::Config::ERROR_HANDLER)
          # Insert a no-op error handler to prevent Sidekiq from logging to STDOUT
          # because of empty error_handlers (see link).
          # https://github.com/mperham/sidekiq/blob/02153c17360e712d9a94c08406fe7c057c4d7635/lib/sidekiq/config.rb#L258
          config.error_handlers << proc {}
        end

        # Add logstash support
        config[:job_logger] = Sidekiq::LogstashJobLogger
        # Set custom formatter for Sidekiq logger
        config.logger.formatter = Sidekiq::Logging::LogstashFormatter.new
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sidekiq-logstash-3.2.1 lib/sidekiq/logstash.rb
sidekiq-logstash-3.2.0 lib/sidekiq/logstash.rb
sidekiq-logstash-3.1.0 lib/sidekiq/logstash.rb