Class: Trema::Logger

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

Overview

The default logger.

Constant Summary collapse

LOGGING_LEVELS =
{ debug: ::Logger::DEBUG,
info: ::Logger::INFO,
warn: ::Logger::WARN,
error: ::Logger::ERROR,
fatal: ::Logger::FATAL,
unknown: ::Logger::UNKNOWN }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Logger

Returns a new instance of Logger.



19
20
21
# File 'lib/trema/logger.rb', line 19

def initialize(name)
  @name = name
end

Instance Method Details

#debug(message) ⇒ Object



43
44
45
# File 'lib/trema/logger.rb', line 43

def debug(message)
  output :debug, message
end

#error(message) ⇒ Object



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

def error(message)
  output :error, message
end

#fatal(message) ⇒ Object



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

def fatal(message)
  output :fatal, message
end

#info(message) ⇒ Object



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

def info(message)
  output :info, message
end

#levelObject



56
57
58
59
# File 'lib/trema/logger.rb', line 56

def level
  @logger ||= create_logger
  @logger[:file].level
end

#level=(level) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/trema/logger.rb', line 47

def level=(level)
  @logger ||= create_logger
  @logger.values.each do |each|
    each.__send__ :level=, LOGGING_LEVELS.fetch(level.to_sym)
  end
rescue KeyError
  raise(ArgumentError, "Invalid log level: #{level}")
end

#unknown(message) ⇒ Object



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

def unknown(message)
  output :unknown, message
end

#warn(message) ⇒ Object



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

def warn(message)
  output :warn, message
end