Class: Clearsale::LoggerFormatterFilter
- Inherits:
-
Object
- Object
- Clearsale::LoggerFormatterFilter
- Defined in:
- lib/clearsale/logger_formatter_filter.rb
Constant Summary collapse
- 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)}" }
Instance Method Summary collapse
- #call(severity, datetime, progname, msg) ⇒ Object
- #filter(msg) ⇒ Object
-
#initialize(tags_to_filter = [], &block) ⇒ LoggerFormatterFilter
constructor
A new instance of LoggerFormatterFilter.
Constructor Details
#initialize(tags_to_filter = [], &block) ⇒ LoggerFormatterFilter
Returns a new instance of LoggerFormatterFilter.
15 16 17 18 |
# File 'lib/clearsale/logger_formatter_filter.rb', line 15 def initialize( = [], &block) @tags_to_filter = @block = block end |
Instance Method Details
#call(severity, datetime, progname, msg) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/clearsale/logger_formatter_filter.rb', line 20 def call(severity, datetime, progname, msg) if @block @block.call(severity, datetime, progname, filter(msg)) else "#{severity} #{datetime} --#{progname}: #{filter(msg)}" end end |
#filter(msg) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/clearsale/logger_formatter_filter.rb', line 6 def 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 |