Module: SidekiqUniqueJobs::Logging

Overview

Utility module for reducing the number of uses of logger.

Author:

Instance Method Summary collapse

Instance Method Details

#log_debug(message_or_exception = nil) { ... } ⇒ Object

Logs a message at debug level

Parameters:

  • message_or_exception (String, Exception) (defaults to: nil)

    the message or exception to log

Yields:

  • the message or exception to use for log message Used for compatibility with logger



17
18
19
20
# File 'lib/sidekiq_unique_jobs/logging.rb', line 17

def log_debug(message_or_exception = nil, &block)
  logger.debug(message_or_exception, &block)
  nil
end

#log_error(message_or_exception = nil) { ... } ⇒ Object

Logs a message at error level

Parameters:

  • message_or_exception (String, Exception) (defaults to: nil)

    the message or exception to log

Yields:

  • the message or exception to use for log message Used for compatibility with logger



44
45
46
47
# File 'lib/sidekiq_unique_jobs/logging.rb', line 44

def log_error(message_or_exception = nil, &block)
  logger.error(message_or_exception, &block)
  nil
end

#log_fatal(message_or_exception = nil) { ... } ⇒ Object

Logs a message at fatal level

Parameters:

  • message_or_exception (String, Exception) (defaults to: nil)

    the message or exception to log

Yields:

  • the message or exception to use for log message Used for compatibility with logger



53
54
55
56
# File 'lib/sidekiq_unique_jobs/logging.rb', line 53

def log_fatal(message_or_exception = nil, &block)
  logger.fatal(message_or_exception, &block)
  nil
end

#log_info(message_or_exception = nil) { ... } ⇒ Object

Logs a message at info level

Parameters:

  • message_or_exception (String, Exception) (defaults to: nil)

    the message or exception to log

Yields:

  • the message or exception to use for log message Used for compatibility with logger



26
27
28
29
# File 'lib/sidekiq_unique_jobs/logging.rb', line 26

def log_info(message_or_exception = nil, &block)
  logger.info(message_or_exception, &block)
  nil
end

#log_warn(message_or_exception = nil) { ... } ⇒ Object

Logs a message at warn level

Parameters:

  • message_or_exception (String, Exception) (defaults to: nil)

    the message or exception to log

Yields:

  • the message or exception to use for log message Used for compatibility with logger



35
36
37
38
# File 'lib/sidekiq_unique_jobs/logging.rb', line 35

def log_warn(message_or_exception = nil, &block)
  logger.warn(message_or_exception, &block)
  nil
end

#loggerObject

A convenience method for using the configured logger



9
10
11
# File 'lib/sidekiq_unique_jobs/logging.rb', line 9

def logger
  SidekiqUniqueJobs.logger
end

#logging_context(middleware_class, job_hash) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/sidekiq_unique_jobs/logging.rb', line 58

def logging_context(middleware_class, job_hash)
  digest = job_hash["unique_digest"]
  if defined?(Sidekiq::Logging)
    "#{middleware_class} #{"DIG-#{digest}" if digest}"
  else
    { middleware: middleware_class, unique_digest: digest }
  end
end