module SidekiqUniqueJobs::Logging

def self.included(base)

def self.included(base)
  base.send(:extend, self)
end

def fake_logger_context(_context)

def fake_logger_context(_context)
  logger.warn "Don't know how to setup the logging context. Please open a feature request:" \
              " https://github.com/mhenrixon/sidekiq-unique-jobs/issues/new?template=feature_request.md"
  yield
end

def log_debug(message_or_exception = nil, &block)

Other tags:
    Yield: - the message or exception to use for log message

Returns:
  • (void) -

Parameters:
  • message_or_exception (String, Exception) -- the message or exception to log
def log_debug(message_or_exception = nil, &block)
  logger.debug(message_or_exception, &block)
  nil
end

def log_error(message_or_exception = nil, &block)

Other tags:
    Yield: - the message or exception to use for log message

Returns:
  • (void) -

Parameters:
  • message_or_exception (String, Exception) -- the message or exception to log
def log_error(message_or_exception = nil, &block)
  logger.error(message_or_exception, &block)
  nil
end

def log_fatal(message_or_exception = nil, &block)

Other tags:
    Yield: - the message or exception to use for log message

Returns:
  • (void) -

Parameters:
  • message_or_exception (String, Exception) -- the message or exception to log
def log_fatal(message_or_exception = nil, &block)
  logger.fatal(message_or_exception, &block)
  nil
end

def log_info(message_or_exception = nil, &block)

Other tags:
    Yield: - the message or exception to use for log message

Returns:
  • (void) -

Parameters:
  • message_or_exception (String, Exception) -- the message or exception to log
def log_info(message_or_exception = nil, &block)
  logger.info(message_or_exception, &block)
  nil
end

def log_warn(message_or_exception = nil, &block)

Other tags:
    Yield: - the message or exception to use for log message

Returns:
  • (void) -

Parameters:
  • message_or_exception (String, Exception) -- the message or exception to log
def log_warn(message_or_exception = nil, &block)
  logger.warn(message_or_exception, &block)
  nil
end

def logger

Returns:
  • (Logger) -

Other tags:
    See: SidekiqUniqueJobs#.logger -
def logger
  SidekiqUniqueJobs.logger
end

def logger_context_hash?

Returns:
  • (true, false) -

Other tags:
    Note: - only used to remove the need for explicitly ignoring manual dispatch in other places.
def logger_context_hash?
  defined?(Sidekiq::Context) || logger_respond_to_with_context?
end

def logger_method

Returns:
  • (proc) - the method to call
def logger_method
  @logger_method ||= sidekiq_context_method
  @logger_method ||= sidekiq_logger_context_method
  @logger_method ||= sidekiq_logging_context_method
  @logger_method ||= no_sidekiq_context_method
end

def logger_respond_to_with_context?

Returns:
  • (true, false) -

Other tags:
    Note: - only used to remove the need for explicitly ignoring manual dispatch in other places.
def logger_respond_to_with_context?
  logger.respond_to?(:with_context)
end

def logging_context

Returns:
  • (Hash) - the context to use for each log line
def logging_context
  raise NotImplementedError, "#{__method__} needs to be implemented in #{self.class}"
end

def no_sidekiq_context_method

def no_sidekiq_context_method
  method(:fake_logger_context)
end

def sidekiq_context_method

def sidekiq_context_method
  Sidekiq::Context.method(:with) if defined?(Sidekiq::Context)
end

def sidekiq_logger_context_method

def sidekiq_logger_context_method
  logger.method(:with_context)           if logger_respond_to_with_context?
end

def sidekiq_logging_context_method

def sidekiq_logging_context_method
  Sidekiq::Logging.method(:with_context) if defined?(Sidekiq::Logging)
end

def with_configured_loggers_context

Other tags:
    Yield: -

Returns:
  • (void) -
def with_configured_loggers_context
  logger_method.call(logging_context) { yield }
end

def with_logging_context

Other tags:
    Yieldreturn: - yield to the middleware instance

Returns:
  • (void) -
def with_logging_context
  with_configured_loggers_context do
    return yield
  end
  nil # Need to make sure we don't return anything here
end