Class: Yell::Silencer

Inherits:
Object
  • Object
show all
Defined in:
lib/yell/silencer.rb

Overview

The Yell::Silencer is your handly helper for stiping out unwanted log messages.

Defined Under Namespace

Classes: PresetNotFound

Constant Summary collapse

Presets =
{
  :assets => [/\AStarted GET "\/assets/, /\AServed asset/, /\A\s*\z/] # for Rails
}

Instance Method Summary collapse

Constructor Details

#initialize(*patterns) ⇒ Silencer

Returns a new instance of Silencer.



16
17
18
# File 'lib/yell/silencer.rb', line 16

def initialize( *patterns )
  @patterns = patterns.dup
end

Instance Method Details

#add(*patterns) ⇒ self

Add one or more patterns to the silencer

Examples:

add( 'password' )
add( 'username', 'password' )

Add regular expressions

add( /password/ )

Returns:

  • (self)

    The silencer instance



30
31
32
33
34
# File 'lib/yell/silencer.rb', line 30

def add( *patterns )
  patterns.each { |pattern| add!(pattern) }

  self
end

#call(*messages) ⇒ Array

Clears out all the messages that would match any defined pattern

Examples:

call(['username', 'password'])
#=> ['username]

Returns:

  • (Array)

    The remaining messages



43
44
45
46
47
# File 'lib/yell/silencer.rb', line 43

def call( *messages )
  return messages if @patterns.empty?

  messages.reject { |m| matches?(m) }
end

#inspectObject

Get a pretty string



50
51
52
# File 'lib/yell/silencer.rb', line 50

def inspect
  "#<#{self.class.name} patterns: #{@patterns.inspect}>"
end

#patternsObject



55
56
57
# File 'lib/yell/silencer.rb', line 55

def patterns
  @patterns
end