Class: Log4r::Outputter::OutputterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/log/patchlog4r.rb

Overview

Log4r creates the logging methods dynamically - quite cleverly creating only those methods that are required, but not that transparent.

To add filter support we ‘monkey patch’ the original implementation of define_log in ‘outputterfactory.rb’ by adding in the filter call. This slows down the run time, but that is not so important.

Class Method Summary collapse

Class Method Details

.define_log(mname, level, out) ⇒ Object

original comment: we need to synch the actual write/format for thread saftyness



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bio/log/patchlog4r.rb', line 13

def self.define_log(mname, level, out)
  return if mname == 'off' || mname == 'all'
  # p [mname,level,out]
  # 
  # At runtime, self and logevent are available to the method:
  # [:self, #<Log4r::StderrOutputter:0x9f8975c @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x9f89694>, @name="stderr", @level=0, @formatter=#<Log4r::DefaultFormatter:0x9f7c174 @depth=7>, @out=#<IO:<STDERR>>>]
  # [:logevent, #<Log4r::LogEvent:0xa198de0 @data="As Developer ERROR should fail", @tracer=nil, @level=4, @name="mylog", @fullname="mylog">]

  mstr = 
      %-
      def out.#{mname}(logevent)
        if self.class.method_defined?(:filtered?) 
          # p logevent
          if !filtered?(logevent.level,nil,logevent.data)
            # p "**** returning nil for "+logevent.data
            return nil
          end
        end
        canonical_log(logevent)
      end
      -
  module_eval mstr
end