Sha256: 4f165c4b226589460e22eb22087ce40ad72c8446d2e219e13fc4e69a681558aa

Contents?: true

Size: 875 Bytes

Versions: 4

Compression:

Stored size: 875 Bytes

Contents

module Clearsale::LoggerFormatterFilter
  
  mattr_accessor :tags_to_filter

  OPEN_TAG   = lambda{ |tag_name| "<#{tag_name}>"   }
  CLOSE_TAG  = lambda{ |tag_name| "<\/#{tag_name}>" }
  TAG_REGEXP = lambda{ |tag_name, content| "#{OPEN_TAG.call(tag_name)}#{content}#{CLOSE_TAG.call(tag_name)}" }

  def self.filter(msg)
    return msg if !msg.respond_to?(:gsub) || tags_to_filter.nil?

    tags_to_filter.each do |tag|
      msg = msg.gsub(%r{#{TAG_REGEXP.call(tag,'.*')}}, TAG_REGEXP.call(tag,"[FILTERED]")) 
    end
    msg
  end

  def self.new_instance(&block)
    if block_given?
      lambda do |severity, datetime, progname, msg|
        block.call(severity, datetime, progname, filter(msg))
      end
    else
      lambda do |severity, datetime, progname, msg|
        "#{severity} #{datetime} --#{progname}: #{filter(msg)}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clearsale-0.1.6 lib/clearsale/logger_formatter_filter.rb
clearsale-0.1.5 lib/clearsale/logger_formatter_filter.rb
clearsale-0.1.4 lib/clearsale/logger_formatter_filter.rb
clearsale-0.1.3 lib/clearsale/logger_formatter_filter.rb