Class: Log4r::Configurator

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/log4r/configurator.rb

Overview

See log4r/configurator.rb

Constant Summary collapse

@@params =
Hash.new

Class Method Summary collapse

Class Method Details

.[](param) ⇒ Object

Get a parameter’s value



25
# File 'lib/log4r/configurator.rb', line 25

def self.[](param); @@params[param] end

.[]=(param, value) ⇒ Object

Define a parameter with a value



27
# File 'lib/log4r/configurator.rb', line 27

def self.[]=(param, value); @@params[param] = value end

.custom_levels(*levels) ⇒ Object

Sets the custom levels. This method accepts symbols or strings.

Configurator.custom_levels('My', 'Custom', :Levels)

Alternatively, you can specify custom levels in XML:

<log4r_config>
  <pre_config>
    <custom_levels>
      My, Custom, Levels
    </custom_levels>
    ...


42
43
44
45
46
47
48
49
50
51
# File 'lib/log4r/configurator.rb', line 42

def self.custom_levels(*levels)
  return Logger.root if levels.size == 0
  for i in 0...levels.size
    name = levels[i].to_s
    if name =~ /\s/ or name !~ /^[A-Z]/
      raise TypeError, "#{name} is not a valid Ruby Constant name", caller
    end
  end
  Log4r.define_levels *levels
end

.load_xml_file(filename) ⇒ Object

Given a filename, loads the XML configuration for Log4r.



54
55
56
57
# File 'lib/log4r/configurator.rb', line 54

def self.load_xml_file(filename)
  detect_rexml
  actual_load Document.new(File.new(filename))
end

.load_xml_string(string) ⇒ Object

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



60
61
62
63
# File 'lib/log4r/configurator.rb', line 60

def self.load_xml_string(string)
  detect_rexml
  actual_load Document.new(string)
end