Class: Log4r::Logger::LoggerFactory
- Inherits:
-
Object
- Object
- Log4r::Logger::LoggerFactory
- Defined in:
- lib/log4r/loggerfactory.rb
Overview
:nodoc:
Class Method Summary collapse
-
.define_methods(logger) ⇒ Object
we want to log iff root.lev <= lev && logger.lev <= lev BTW, root is guaranteed to be defined by this point.
- .set_false(logger, lname) ⇒ Object
-
.set_log(logger, lname) ⇒ Object
Logger logging methods are defined here.
- .set_true(logger, lname) ⇒ Object
-
.toggle_methods(globlev, logger) ⇒ Object
toggle methods >= globlev that are also >= level.
-
.undefine_methods(logger) ⇒ Object
set logging methods to null defaults.
-
.unset_log(logger, lname) ⇒ Object
And now, the weird dynamic method definitions! :).
Class Method Details
.define_methods(logger) ⇒ Object
we want to log iff root.lev <= lev && logger.lev <= lev BTW, root is guaranteed to be defined by this point
14 15 16 17 18 19 20 |
# File 'lib/log4r/loggerfactory.rb', line 14 def self.define_methods(logger) return if logger.is_root? undefine_methods(logger) globlev = Repository['root'].level return if logger.level == OFF or globlev == OFF toggle_methods(globlev, logger) end |
.set_false(logger, lname) ⇒ Object
79 80 81 |
# File 'lib/log4r/loggerfactory.rb', line 79 def self.set_false(logger, lname) module_eval "def logger.#{lname.downcase}?; false end" end |
.set_log(logger, lname) ⇒ Object
Logger logging methods are defined here.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/log4r/loggerfactory.rb', line 58 def self.set_log(logger, lname) # invoke caller iff the logger invoked is tracing tracercall = (logger.trace ? "caller" : "nil") # maybe pass parent a logevent. second arg is the switch if logger.additive && !logger.parent.is_root? parentcall = "@parent.#{lname.downcase}(event, true)" end mstr = %- def logger.#{lname.downcase}(data=nil, propagated=false) if propagated then event = data else data = yield if block_given? event = LogEvent.new(#{lname}, self, #{tracercall}, data) end @outputters.each {|o| o.#{lname.downcase}(event) } #{parentcall} end - module_eval mstr end |
.set_true(logger, lname) ⇒ Object
83 84 85 |
# File 'lib/log4r/loggerfactory.rb', line 83 def self.set_true(logger, lname) module_eval "def logger.#{lname.downcase}?; true end" end |
.toggle_methods(globlev, logger) ⇒ Object
toggle methods >= globlev that are also >= level
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/log4r/loggerfactory.rb', line 34 def self.toggle_methods(globlev, logger) for lev in globlev...LEVELS # satisfies >= globlev next if lev < logger.level # satisfies >= level next if LNAMES[lev] == 'OFF' next if LNAMES[lev] == 'ALL' set_log(logger, LNAMES[lev]) set_true(logger, LNAMES[lev]) end if logger.level == ALL set_true(logger, 'all') end if logger.level != OFF && globlev != OFF set_false(logger, 'off') end end |
.undefine_methods(logger) ⇒ Object
set logging methods to null defaults
23 24 25 26 27 28 29 30 31 |
# File 'lib/log4r/loggerfactory.rb', line 23 def self.undefine_methods(logger) for lname in LNAMES next if lname == 'OFF'|| lname == 'ALL' unset_log(logger, lname) set_false(logger, lname) end set_false(logger, 'all') set_true(logger, 'off') end |
.unset_log(logger, lname) ⇒ Object
And now, the weird dynamic method definitions! :)
52 53 54 55 |
# File 'lib/log4r/loggerfactory.rb', line 52 def self.unset_log(logger, lname) mstr="def logger.#{lname.downcase}(data=nil, propagated=false); end" module_eval mstr end |