Class: UnitF::Logging::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/unitf/logging/logger.rb

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



13
14
15
16
# File 'lib/unitf/logging/logger.rb', line 13

def initialize
  @writers = []
  self.level = ENV['UNITF_LOG_LEVEL'] || INFO
end

Instance Method Details

#add_writer(writer) ⇒ Object



18
19
20
21
# File 'lib/unitf/logging/logger.rb', line 18

def add_writer(writer)
  @writers << writer
  writer.level = @level
end

#consoleObject



53
54
55
56
57
58
# File 'lib/unitf/logging/logger.rb', line 53

def console
  @writers.each do |writer|
    return writer if writer.is_a?(UnitF::Logging::ConsoleWriter)
  end
  nil
end

#debug(message) ⇒ Object



23
24
25
# File 'lib/unitf/logging/logger.rb', line 23

def debug(message)
  write(DEBUG, message)
end

#dumpObject



60
61
62
63
64
# File 'lib/unitf/logging/logger.rb', line 60

def dump
  @writers.each do |writer|
    puts "Name: #{writer.name} Type: #{writer.class}"
  end
end

#error(message) ⇒ Object



35
36
37
# File 'lib/unitf/logging/logger.rb', line 35

def error(message)
  write(ERROR, message)
end

#fatal(message) ⇒ Object



39
40
41
# File 'lib/unitf/logging/logger.rb', line 39

def fatal(message)
  write(FATAL, message)
end

#info(message) ⇒ Object



27
28
29
# File 'lib/unitf/logging/logger.rb', line 27

def info(message)
  write(INFO, message)
end

#level=(new_level) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/unitf/logging/logger.rb', line 43

def level=(new_level)
  new_level = UnitF::Logging.const_get(new_level.upcase) if new_level.is_a?(String)
  @level = new_level
  @writers.each do |writer|
    writer.level = @level
  end
rescue ArgumentError, NameError
  self.level = INFO
end

#warn(message) ⇒ Object



31
32
33
# File 'lib/unitf/logging/logger.rb', line 31

def warn(message)
  write(WARN, message)
end

#write(severity, message) ⇒ Object



66
67
68
69
70
# File 'lib/unitf/logging/logger.rb', line 66

def write(severity, message)
  @writers.each do |writer|
    writer.log(severity, message)
  end
end