Module: SidekiqUniqueJobs::Logging
- Included in:
- BatchDelete, SidekiqUniqueJobs::Lock::BaseLock, LockArgs, LockDigest, Locksmith, Middleware, OnConflict::Log, OnConflict::Reschedule, OnConflict::Strategy, Orphans::Observer, Orphans::Reaper, Redis::Entity, UpgradeLocks
- Defined in:
- lib/sidekiq_unique_jobs/logging.rb,
lib/sidekiq_unique_jobs/logging/middleware_context.rb
Overview
Provides the sidekiq middleware that makes the gem work
Defined Under Namespace
Modules: Middleware
Class Method Summary collapse
Instance Method Summary collapse
-
#build_message(message_or_exception, item = nil) ⇒ String
Build a log message.
-
#log_debug(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
Logs a message at debug level.
-
#log_error(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
Logs a message at error level.
-
#log_fatal(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
Logs a message at fatal level.
-
#log_info(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
Logs a message at info level.
-
#log_warn(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
Logs a message at warn level.
-
#logger ⇒ Logger
A convenience method for using the configured gem logger.
-
#logging_context ⇒ Hash
Setup some variables to add to each log line.
-
#with_configured_loggers_context { ... } ⇒ void
Attempt to setup context aware logging for the given logger.
-
#with_logging_context ⇒ void
Wraps the middleware logic with context aware logging.
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 8 def self.included(base) base.send(:extend, self) end |
Instance Method Details
#build_message(message_or_exception, item = nil) ⇒ String
Build a log message
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 117 def (, item = nil) return nil if .nil? return if item.nil? = .dup details = item.slice(LOCK, QUEUE, CLASS, JID, LOCK_DIGEST).each_with_object([]) do |(key, value), memo| memo << "#{key}=#{value}" end << " (" << details.join(" ") << ")" end |
#log_debug(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
This method returns an undefined value.
Logs a message at debug level
32 33 34 35 36 37 38 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 32 def log_debug( = nil, item = nil, &block) return unless logging? = (, item) logger.debug(, &block) nil end |
#log_error(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
This method returns an undefined value.
Logs a message at error level
83 84 85 86 87 88 89 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 83 def log_error( = nil, item = nil, &block) return unless logging? = (, item) logger.error(, &block) nil end |
#log_fatal(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
This method returns an undefined value.
Logs a message at fatal level
100 101 102 103 104 105 106 107 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 100 def log_fatal( = nil, item = nil, &block) return unless logging? = (, item) logger.fatal(, &block) nil end |
#log_info(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
This method returns an undefined value.
Logs a message at info level
49 50 51 52 53 54 55 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 49 def log_info( = nil, item = nil, &block) return unless logging? = (, item) logger.info(, &block) nil end |
#log_warn(message_or_exception = nil, item = nil) {|String, Exception| ... } ⇒ void
This method returns an undefined value.
Logs a message at warn level
66 67 68 69 70 71 72 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 66 def log_warn( = nil, item = nil, &block) return unless logging? = (, item) logger.warn(, &block) nil end |
#logger ⇒ Logger
A convenience method for using the configured gem logger
19 20 21 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 19 def logger SidekiqUniqueJobs.logger end |
#logging_context ⇒ Hash
Setup some variables to add to each log line
166 167 168 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 166 def logging_context raise NotImplementedError, "#{__method__} needs to be implemented in #{self.class}" end |
#with_configured_loggers_context { ... } ⇒ void
This method returns an undefined value.
Attempt to setup context aware logging for the given logger
156 157 158 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 156 def with_configured_loggers_context(&block) logger_method.call(logging_context, &block) end |
#with_logging_context ⇒ void
This method returns an undefined value.
Wraps the middleware logic with context aware logging
140 141 142 143 144 145 146 |
# File 'lib/sidekiq_unique_jobs/logging.rb', line 140 def with_logging_context with_configured_loggers_context do return yield end nil # Need to make sure we don't return anything here end |