Class: Log4Ruby::Level
- Inherits:
-
Object
- Object
- Log4Ruby::Level
- Defined in:
- lib/log4ruby/level.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the level.
-
#weight ⇒ Object
readonly
The weight of this level.
Class Method Summary collapse
-
.parse(name) ⇒ Log4Ruby::Level
Parses the specified string in an attempt to convert it to a Level object.
-
.register(name, weight) ⇒ Object
Creates a new level with the specified name and weight.
Instance Method Summary collapse
-
#<(other) ⇒ Object
Check if this level is less than the specified other log level.
-
#<=(other) ⇒ Object
Check if this level is less than or equal to the specified other log level.
-
#==(other) ⇒ Object
Check if this level is equal to the specified other log level.
-
#>(other) ⇒ Object
Check if this level is greater than the specified other log level.
-
#>=(other) ⇒ Object
Check if this level is greater than or equal to the specified other log level.
-
#initialize(name, weight) ⇒ Level
constructor
Creates a new level.
-
#to_s ⇒ String
Override to return the name of the level.
Constructor Details
#initialize(name, weight) ⇒ Level
Creates a new level.
58 59 60 61 |
# File 'lib/log4ruby/level.rb', line 58 def initialize(name, weight) @name = name @weight = weight end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the level.
52 53 54 |
# File 'lib/log4ruby/level.rb', line 52 def name @name end |
#weight ⇒ Object (readonly)
The weight of this level. Higher the value, more severe the log.
50 51 52 |
# File 'lib/log4ruby/level.rb', line 50 def weight @weight end |
Class Method Details
.parse(name) ⇒ Log4Ruby::Level
Parses the specified string in an attempt to convert it to a Level object.
44 45 46 47 |
# File 'lib/log4ruby/level.rb', line 44 def self.parse(name) name = name.upcase const_get(name) end |
.register(name, weight) ⇒ Object
Creates a new level with the specified name and weight. Only level’s created using this method are automatically made available on the Logger class. Any other level’s will have to be handled manually. The method with which it is made available is the same as the level, but with all lowercase characters.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/log4ruby/level.rb', line 18 def self.register(name, weight) name = name.upcase method_name = name.downcase query_method_name = "#{method_name}?" level = Level.new(name, weight) const_set(name, level) # Create the logging method. Logger.send(:define_method, method_name) do |, parameters = {}| return if self.closed? return if level < self.effective_level # Construct the log and dispatch it. parameters[:message] = parameters[:level] = level parameters[:logger] = self self.process_log(Log.new(parameters)) end # Create the query method - for checking the effective level of a logger / appender. Logger.send(:define_method, query_method_name) { self.effective_level <= level } Appender.send(:define_method, query_method_name) { self.level <= level } end |
Instance Method Details
#<(other) ⇒ Object
Check if this level is less than the specified other log level. Comparison is done using the weight attribute
75 76 77 |
# File 'lib/log4ruby/level.rb', line 75 def <(other) self.weight < other.weight end |
#<=(other) ⇒ Object
Check if this level is less than or equal to the specified other log level. Comparison is done using the weight attribute
83 84 85 |
# File 'lib/log4ruby/level.rb', line 83 def <=(other) self.weight <= other.weight end |
#==(other) ⇒ Object
Check if this level is equal to the specified other log level. Comparison is done using the weight attribute
67 68 69 |
# File 'lib/log4ruby/level.rb', line 67 def ==(other) self.weight == other.weight end |
#>(other) ⇒ Object
Check if this level is greater than the specified other log level. Comparison is done using the weight attribute
91 92 93 |
# File 'lib/log4ruby/level.rb', line 91 def >(other) self.weight > other.weight end |
#>=(other) ⇒ Object
Check if this level is greater than or equal to the specified other log level. Comparison is done using the weight attribute
99 100 101 |
# File 'lib/log4ruby/level.rb', line 99 def >=(other) self.weight <= other.weight end |
#to_s ⇒ String
Override to return the name of the level.
106 107 108 |
# File 'lib/log4ruby/level.rb', line 106 def to_s @name end |