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.



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

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



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

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



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

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

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

#inspectObject

Get a pretty string



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

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

#patternsObject



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

def patterns
  @patterns
end