Parent

Log4r::YamlConfigurator

See log4r/yamlconfigurator.rb

Constants

ExcludeParams

Public Class Methods

[](param) click to toggle source

Get a parameter’s value

    # File lib/log4r/yamlconfigurator.rb, line 24
24:     def self.[](param); @@params[param] end
[]=(param, value) click to toggle source

Define a parameter with a value

    # File lib/log4r/yamlconfigurator.rb, line 26
26:     def self.[]=(param, value); @@params[param] = value end
custom_levels( levels) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 29
29:     def self.custom_levels( levels)
30:       return Logger.root if levels.size == 0
31:       for i in 0...levels.size
32:         name = levels[i].to_s
33:         if name =~ /\s/ or name !~ /^[A-Z]/
34:           raise TypeError, "#{name} is not a valid Ruby Constant name", caller
35:         end
36:       end
37:       Log4r.define_levels *levels
38:     end
load_yaml_file( filename) click to toggle source

Given a filename, loads the YAML configuration for Log4r.

    # File lib/log4r/yamlconfigurator.rb, line 41
41:     def self.load_yaml_file( filename)
42:       actual_load( File.open( filename))
43:     end
load_yaml_string( string) click to toggle source

You can load a String YAML configuration instead of a file.

    # File lib/log4r/yamlconfigurator.rb, line 46
46:     def self.load_yaml_string( string)
47:       actual_load( string)
48:     end

Private Class Methods

actual_load( yaml_docs) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 54
54:     def self.actual_load( yaml_docs)
55:       log4r_config = nil
56:       YAML.load_documents( yaml_docs){ |doc|
57:         doc.has_key?( 'log4r_config') and log4r_config = doc['log4r_config'] and break
58:       }
59:       if log4r_config.nil?
60:         raise ConfigError, 
61:         "Key 'log4r_config:' not defined in yaml documents", caller[1..1]
62:       end
63:       decode_yaml( log4r_config)
64:     end
decode_custom_levels( levels) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 81
81:     def self.decode_custom_levels( levels)
82:       return Logger.root if levels.nil?
83:       begin custom_levels( levels)
84:       rescue TypeError => te
85:         raise ConfigError, te.message, caller[1..4]
86:       end
87:     end
decode_formatter( fo) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 137
137:     def self.decode_formatter( fo)
138:       return nil if fo.nil?
139:       type = fo['type'] 
140:       raise ConfigError, "Formatter missing type", caller[1..4] if type.nil?
141:       begin
142:         return Log4r.const_get(type).new(decode_hash_params(fo))
143:       rescue Exception => ae
144:         raise ConfigError,
145:         "Problem creating outputter: #{ae.message}", caller[1..4]
146:       end
147:     end
decode_hash_params(ph) click to toggle source

Does the fancy parameter to hash argument transformation

     # File lib/log4r/yamlconfigurator.rb, line 152
152:     def self.decode_hash_params(ph)
153:       case ph
154:       when Hash
155:         ph.inject({}){|a,(k,v)| a[k] = self.decode_hash_params(v); a}
156:       when Array
157:         ph.map{|v| self.decode_hash_params(v)}
158:       when String
159:         self.paramsub(ph)
160:       else
161:         ph
162:       end
163:     end
decode_logger( lo) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 173
173:     def self.decode_logger( lo)
174:       l = Logger.new lo['name']
175:       decode_logger_common( l, lo)
176:     end
decode_logger_common( l, lo) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 185
185:     def self.decode_logger_common( l, lo)
186:       level    = lo['level']
187:       additive = lo['additive']
188:       trace    = lo['trace']
189:       l.level    = LNAMES.index( level) unless level.nil?
190:       l.additive = additive unless additive.nil?
191:       l.trace    = trace unless trace.nil?
192:       # and now for outputters
193:       outs = lo['outputters']
194:       outs.each {|n| l.add n.strip} unless outs.nil?
195:     end
decode_logserver( lo) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 178
178:     def self.decode_logserver( lo)
179:       name = lo['name']
180:       uri  = lo['uri']
181:       l = LogServer.new name, uri
182:       decode_logger_common(l, lo)
183:     end
decode_outputter( op) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 102
102:     def self.decode_outputter( op)
103:       # fields
104:       name = op['name']
105:       type = op['type']
106:       level = op['level']
107:       only_at = op['only_at']
108:       # validation
109:       raise ConfigError, "Outputter missing name", caller[1..3] if name.nil?
110:       raise ConfigError, "Outputter missing type", caller[1..3] if type.nil?
111:       Log4rTools.validate_level(LNAMES.index(level)) unless level.nil?
112:       only_levels = []
113:       unless only_at.nil?
114:         for lev in only_at
115:           alev = LNAMES.index(lev)
116:           Log4rTools.validate_level(alev, 3)
117:           only_levels.push alev
118:         end
119:       end
120: 
121:       formatter = decode_formatter( op['formatter'])
122: 
123:       opts = {}
124:       opts[:level] = LNAMES.index(level) unless level.nil?
125:       opts[:formatter] = formatter unless formatter.nil?
126:       opts.merge!(decode_hash_params(op))
127:       begin
128:         Outputter[name] = Log4r.const_get(type).new name, opts
129:       rescue Exception => ae
130:         raise ConfigError, 
131:         "Problem creating outputter: #{ae.message}", caller[1..3]
132:       end
133:       Outputter[name].only_at( *only_levels) if only_levels.size > 0
134:       Outputter[name]
135:     end
decode_parameters( params) click to toggle source
     # File lib/log4r/yamlconfigurator.rb, line 98
 98:     def self.decode_parameters( params)
 99:       params.each{ |p| @@params[p['name']] = p['value']} unless params.nil?
100:     end
decode_pre_config( pre) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 73
73:     def self.decode_pre_config( pre)
74:       return Logger.root if pre.nil?
75:       decode_custom_levels( pre['custom_levels'])
76:       global_config( pre['global'])
77:       global_config( pre['root'])
78:       decode_parameters( pre['parameters'])
79:     end
decode_yaml( cfg) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 66
66:     def self.decode_yaml( cfg)
67:       decode_pre_config( cfg['pre_config'])
68:       cfg['outputters'].each{ |op| decode_outputter( op)}
69:       cfg['loggers'].each{ |lo| decode_logger( lo)}
70:       cfg['logserver'].each{ |lo| decode_logserver( lo)} unless cfg['logserver'].nil?
71:     end
global_config( e) click to toggle source
    # File lib/log4r/yamlconfigurator.rb, line 89
89:     def self.global_config( e)
90:       return if e.nil?
91:       globlev = e['level']
92:       return if globlev.nil?
93:       lev = LNAMES.index(globlev)     # find value in LNAMES
94:       Log4rTools.validate_level(lev, 4)  # choke on bad level
95:       Logger.global.level = lev
96:     end
paramsub(str) click to toggle source

Substitues any #{foo} in the YAML with Parameter[‘foo’]

     # File lib/log4r/yamlconfigurator.rb, line 166
166:     def self.paramsub(str)
167:       @@params.each {|param, value|
168:         str = str.sub("\#{#{param}}", value)
169:       }
170:       str
171:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.