Module: ApiHammer::RailsOrSidekiqLogger
- Extended by:
- RailsOrSidekiqLogger
- Included in:
- RailsOrSidekiqLogger
- Defined in:
- lib/api_hammer/rails_or_sidekiq_logger.rb
Overview
include in a class to define #logger which will switch between Sidekiq and Rails using RailsOrSidekiqLoggerMiddleware
class Foo
include ApiHammer::RailsOrSidekiqLogger
end
Constant Summary collapse
- LOGGER_KEY =
'api_hammer_rails_or_sidekiq_logger'
Instance Method Summary collapse
Instance Method Details
#logger ⇒ Object
36 37 38 39 |
# File 'lib/api_hammer/rails_or_sidekiq_logger.rb', line 36 def logger logger = Thread.current[LOGGER_KEY] || ::Rails.logger logger.respond_to?(:tagged) ? logger : ::ActiveSupport::TaggedLogging.new(logger) end |
#with_logger(logger) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/api_hammer/rails_or_sidekiq_logger.rb', line 26 def with_logger(logger) orig_logger = Thread.current[LOGGER_KEY] begin Thread.current[LOGGER_KEY] = logger yield ensure Thread.current[LOGGER_KEY] = orig_logger end end |