Class: LogFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/log_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#formatObject

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, message)
    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]] = message

    return @format
end