Class: Log4r::Outputter::OutputterFactory
- Inherits:
-
Object
- Object
- Log4r::Outputter::OutputterFactory
- Includes:
- Singleton
- Defined in:
- lib/log4r/outputter/outputterfactory.rb
Overview
:nodoc:
Class Method Summary collapse
-
.create_methods(out, levels = nil) ⇒ Object
handles two cases: logging above a level (no second arg specified) or logging a set of levels (passed into the second argument).
-
.define_log(mname, level, out) ⇒ Object
we need to synch the actual write/format for thread safteyness.
- .undefine_log(mname, out) ⇒ Object
Class Method Details
.create_methods(out, levels = nil) ⇒ Object
handles two cases: logging above a level (no second arg specified) or logging a set of levels (passed into the second argument)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/log4r/outputter/outputterfactory.rb', line 18 def self.create_methods(out, levels=nil) Logger.root # force levels to be loaded # first, undefine all the log levels for mname in LNAMES undefine_log(mname.downcase, out) end if not levels.nil? and levels.include? OFF raise TypeError, "Can't log only_at OFF", caller[1..-1] end return out if out.level == OFF if levels.nil? # then define the log methods for lev >= outlev for lev in out.level...LEVELS define_log(LNAMES[lev].downcase, lev, out) end else # define the logs only for assigned levels for lev in levels define_log(LNAMES[lev].downcase, lev, out) end end return out end |
.define_log(mname, level, out) ⇒ Object
we need to synch the actual write/format for thread safteyness
43 44 45 46 47 48 49 50 51 |
# File 'lib/log4r/outputter/outputterfactory.rb', line 43 def self.define_log(mname, level, out) return if mname == 'off' || mname == 'all' mstr = %- def out.#{mname}(logevent) canonical_log(logevent) end - module_eval mstr end |
.undefine_log(mname, out) ⇒ Object
53 54 55 56 57 |
# File 'lib/log4r/outputter/outputterfactory.rb', line 53 def self.undefine_log(mname, out) return if mname == 'off' || mname == 'all' mstr = "def out.#{mname}(logevent); end" module_eval mstr end |