Class: LogFormatter
- Inherits:
-
Object
- Object
- LogFormatter
- Defined in:
- lib/log_formatter.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
Instance Method Summary collapse
-
#initialize(format) ⇒ LogFormatter
constructor
A new instance of LogFormatter.
- #interpret(logger, level, message) ⇒ Object
Constructor Details
#initialize(format) ⇒ LogFormatter
Returns a new instance of LogFormatter.
5 6 7 |
# File 'lib/log_formatter.rb', line 5 def initialize format @format = format end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/log_formatter.rb', line 3 def format @format end |
Instance Method Details
#interpret(logger, level, message) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/log_formatter.rb', line 9 def interpret(logger, level, ) time = Time.new values = ["${TIME}", "${NAME}", "${LEVEL}", "${MESSAGE}"] values.each do |value| if !@format.include? value puts "Error: You forget a parameter in the log formatter." exit end end @format[values[0]] = time.hour.inspect + ":" + time.min.inspect + ":" + time.sec.inspect @format[values[1]] = logger.name @format[values[2]] = level.name @format[values[3]] = return @format end |