lib/sidekiq/logstash.rb in sidekiq-logstash-2.0.3 vs lib/sidekiq/logstash.rb in sidekiq-logstash-3.0.0

- old
+ new

@@ -20,24 +20,21 @@ 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) } + # 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 - 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 - + config[:job_logger] = Sidekiq::LogstashJobLogger # Set custom formatter for Sidekiq logger config.logger.formatter = Sidekiq::Logging::LogstashFormatter.new end end end