Class: TaggedLogger::TagMatcher
- Inherits:
-
Object
- Object
- TaggedLogger::TagMatcher
- Defined in:
- lib/tagged_logger/tagged_logger.rb
Constant Summary collapse
- LEVELS =
{ :debug => 1, :info => 2, :warn => 3, :error => 4, :fatal => 5}
Instance Attribute Summary collapse
-
#match_spec ⇒ Object
readonly
Returns the value of attribute match_spec.
Class Method Summary collapse
Instance Method Summary collapse
- #above_treshold(level) ⇒ Object
-
#initialize(match_spec, level = nil) ⇒ TagMatcher
constructor
A new instance of TagMatcher.
- #match?(tag, level = nil) ⇒ Boolean
Constructor Details
#initialize(match_spec, level = nil) ⇒ TagMatcher
Returns a new instance of TagMatcher.
100 101 102 103 |
# File 'lib/tagged_logger/tagged_logger.rb', line 100 def initialize(match_spec, level = nil) @level = level || :debug @match_spec = match_spec end |
Instance Attribute Details
#match_spec ⇒ Object (readonly)
Returns the value of attribute match_spec.
97 98 99 |
# File 'lib/tagged_logger/tagged_logger.rb', line 97 def match_spec @match_spec end |
Class Method Details
.match?(spec, tag) ⇒ Boolean
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tagged_logger/tagged_logger.rb', line 114 def self.match?(spec, tag) t = tag.to_s result = case spec when Regexp t =~ spec when Class t == spec.name when Array spec.any? {|s| match?(s, tag)} else spec.to_s == t end return result if result self.match?(spec, tag.superclass) if tag.class == Class && tag.superclass != Class end |
Instance Method Details
#above_treshold(level) ⇒ Object
110 111 112 |
# File 'lib/tagged_logger/tagged_logger.rb', line 110 def above_treshold(level) LEVELS[@level] <= LEVELS[level] end |
#match?(tag, level = nil) ⇒ Boolean
105 106 107 108 |
# File 'lib/tagged_logger/tagged_logger.rb', line 105 def match?(tag, level = nil) return false if level && !above_treshold(level) self.class.match?(@match_spec, tag) end |