Module: SidekiqUniqueJobs::Logging::Middleware

Includes:
SidekiqUniqueJobs::Logging
Included in:
SidekiqUniqueJobs::Lock::WhileExecuting, Middleware
Defined in:
lib/sidekiq_unique_jobs/logging/middleware_context.rb

Overview

Context aware logging for Sidekiq Middlewares

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SidekiqUniqueJobs::Logging

#build_message, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #with_configured_loggers_context, #with_logging_context

Class Method Details

.included(base) ⇒ Object



18
19
20
21
22
# File 'lib/sidekiq_unique_jobs/logging/middleware_context.rb', line 18

def self.included(base)
  base.class_eval do
    extend Logging::Middleware
  end
end

Instance Method Details

#logging_contextHash, String

Provides a logging context for Sidekiq Middlewares

Returns:

  • (Hash)

    when logger responds to ‘:with_context`

  • (String)

    when logger does not responds to ‘:with_context`



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sidekiq_unique_jobs/logging/middleware_context.rb', line 31

def logging_context
  middleware = is_a?(SidekiqUniqueJobs::Middleware::Client) ? :client : :server
  digest     = item[LOCK_DIGEST]
  lock_type  = item[LOCK]

  if logger_context_hash?
    { "uniquejobs" => middleware, lock_type => digest }
  else
    "uniquejobs-#{middleware} #{"DIG-#{digest}" if digest}"
  end
end