Sha256: d06440ea067b38f5f3d7161e0ae6f356d60313df335d6dc4c4dc05227be7b149

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

if defined?(ActiveSupport::BroadcastLogger)
  module ActiveSupport
    module TaggedLogging
      # This module is included in ActiveSupport::BroadcastLogger to enable
      # broadcasting to tagged loggers with equivalent semantics.
      module Broadcasting
        def tagged(*tags, &block)
          return super unless broadcasts.any? { |logger| logger.respond_to?(:tagged) }

          if block_given?
            # `tagged(...) { |logger| ... }` yields itself to the block
            broadcasts.inject(block) do |block, logger|
              if logger.respond_to?(:tagged)
                proc { logger.tagged(*tags) { block.call(self) } }
              else
                block
              end
            end.call
          else
            # `tagged(...) returns a new logger with the tags pushed
            self.class.new(*broadcasts.map { |logger|
              logger.respond_to?(:tagged) ? logger.tagged(*tags) : logger
            })
          end
        end
      end
    end
  end

  ActiveSupport::BroadcastLogger.include(ActiveSupport::TaggedLogging::Broadcasting)
else
  warn "[Activesupport::TaggedLogging] ActiveSupport::BroadcastLogger is not available, therefore broadcasting to tagged loggers is not supported."
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activesupport-tagged_logging-2.0.3 lib/activesupport/tagged_logging/broadcasting.rb
activesupport-tagged_logging-2.0.2 lib/activesupport/tagged_logging/broadcasting.rb
activesupport-tagged_logging-2.0.1 lib/activesupport/tagged_logging/broadcasting.rb
activesupport-tagged_logging-2.0.0 lib/activesupport/tagged_logging/broadcasting.rb
activesupport-tagged_logging-1.0.0 lib/activesupport/tagged_logging/broadcasting.rb