Sha256: c7d78a32aeed2b0507abf1ceb5842c3d91093af6305b9846939b6479a0f40e9a

Contents?: true

Size: 757 Bytes

Versions: 16

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

require 'logger'

module FilteringLogger
  attr_reader :filters

  def filters=(f)
    raise ArgumentError, "Must provide an array" unless f.is_a?(Array)

    @filters = f
  end

  def add(s, m = nil, p = nil, &blk)
    p ||= @progname

    if @filters && p
      @filters.each do |re, sev|
        if re === p
          if s < sev
            return true
          else
            # We force the severity to nil for this call to override
            # the logger's default severity filtering logic, because
            # messages without a severity are always logged
            return super(nil, m, p, &blk)
          end
        end
      end
    end

    super
  end

  alias log add
end

Logger.prepend(FilteringLogger)

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 lib/service_skeleton/filtering_logger.rb
service_skeleton-2.1.0 lib/service_skeleton/filtering_logger.rb
service_skeleton-1.0.5 lib/service_skeleton/filtering_logger.rb
service_skeleton-2.0.2 lib/service_skeleton/filtering_logger.rb
service_skeleton-2.0.1 lib/service_skeleton/filtering_logger.rb
service_skeleton-2.0.0 lib/service_skeleton/filtering_logger.rb
service_skeleton-1.0.4 lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.1.ENOTAG lib/service_skeleton/filtering_logger.rb
service_skeleton-1.0.3 lib/service_skeleton/filtering_logger.rb
service_skeleton-1.0.2 lib/service_skeleton/filtering_logger.rb
service_skeleton-1.0.1 lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.49.g47046b9 lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.48.g4a40599 lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.44.g75d07d7 lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.43.g678698a lib/service_skeleton/filtering_logger.rb
service_skeleton-0.0.0.41.g9507cda lib/service_skeleton/filtering_logger.rb