Sha256: da85866689120d5cc2982f86384f2174a787a8645f41e52b57910b84f4bf5699

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

module RailsSemanticLogger
  module Sidekiq
    module Defaults
      # Prevent exception logging during standard error handling since the Job Logger below already logs the exception.
      ERROR_HANDLER =
        if ::Sidekiq::VERSION.to_f < 7.1 ||
           (::Sidekiq::VERSION.to_f == 7.1 && ::Sidekiq::VERSION.split(".").last.to_i < 6)
          lambda do |_ex, ctx|
            unless ctx.empty?
              job_hash = ctx[:job] || {}
              klass    = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
              logger   = klass ? SemanticLogger[klass] : Sidekiq.logger
              ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
            end
          end
        else
          lambda do |_ex, ctx, _default_configuration|
            unless ctx.empty?
              job_hash = ctx[:job] || {}
              klass    = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
              logger   = klass ? SemanticLogger[klass] : Sidekiq.logger
              ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
            end
          end
        end

      # Returns the default logger after removing from the supplied list.
      # Returns [nil] when the default logger was not present.
      def self.delete_default_error_handler(error_handlers)
        return error_handlers.delete(::Sidekiq::Config::ERROR_HANDLER) if defined?(::Sidekiq::Config::ERROR_HANDLER)
        return error_handlers.delete(::Sidekiq::DEFAULT_ERROR_HANDLER) if defined?(::Sidekiq::DEFAULT_ERROR_HANDLER)

        return unless defined?(::Sidekiq::ExceptionHandler)

        existing = error_handlers.find { |handler| handler.is_a?(::Sidekiq::ExceptionHandler::Logger) }
        error_handlers.delete(existing) if existing
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_semantic_logger-4.17.0 lib/rails_semantic_logger/sidekiq/defaults.rb