Class: Sidecloq::Utils::ContextLogger
- Inherits:
-
Object
- Object
- Sidecloq::Utils::ContextLogger
- Defined in:
- lib/sidecloq/utils.rb
Overview
Sets the Sidekiq::Logging context automatically with direct calls to *.logger
Instance Method Summary collapse
-
#initialize(ctx) ⇒ ContextLogger
constructor
A new instance of ContextLogger.
- #method_missing(meth, *args) ⇒ Object
- #sidekiq_logging_context_method ⇒ Object
Constructor Details
#initialize(ctx) ⇒ ContextLogger
Returns a new instance of ContextLogger.
7 8 9 |
# File 'lib/sidecloq/utils.rb', line 7 def initialize(ctx) @context = ctx end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
27 28 29 30 31 |
# File 'lib/sidecloq/utils.rb', line 27 def method_missing(meth, *args) sidekiq_logging_context_method.call(@context) do Sidekiq.logger.send(meth, *args) end end |
Instance Method Details
#sidekiq_logging_context_method ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sidecloq/utils.rb', line 11 def sidekiq_logging_context_method @sidekiq_logging_context_method ||= begin if defined? Sidekiq::Logging # sidekiq < 6 Sidekiq::Logging.method(:with_context) elsif defined?(Sidekiq::Context) # sidekiq 6, <= 6.0.1 Sidekiq::Context.method(:with) else # sidekiq 6, master Sidekiq.logger.method(:with_context) end end end |