Module: Bio::Log::LoggerFilter

Included in:
LoggerPlus
Defined in:
lib/bio/log/loggerfilter.rb

Overview

The filter logger changes behaviour

Instance Method Summary collapse

Instance Method Details

#filter(&filter_func) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bio/log/loggerfilter.rb', line 8

def filter &filter_func
  @use_filter = filter_func
  @outputters.each do | out | 
    # p [:adding_filter_to,out]
    out.class.send(:define_method, :filtered?) do |l,s,m|
      # p [:called,l,s,m]
      filter_func.call(l,s,m)
    end
    raise 'hell' if !out.class.method_defined?(:filtered?)
  end
  @level = default_level  # will recreate logger methods
  @sub_level = default_sub_level
end

#reset_filterObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/bio/log/loggerfilter.rb', line 22

def reset_filter
  @use_filter = nil
  @outputters.each do | out | 
    if out.class.method_defined?(:filtered?)
      out.class.send(:remove_method, :filtered?)
    end
  end
  @level = default_level  # will recreate logger methods
  @sub_level = default_sub_level
end