Class: TileUp::Logger

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

Overview

Base logger class, subclass this, do not use directly.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, options = {}) ⇒ Logger

create logger set to given level where level is a symbol (:debug, :info, :warn, :error, :fatal) options may specifiy verbose, which will log more info messages



31
32
33
34
35
36
# File 'lib/tileup/logger.rb', line 31

def initialize(level, options = {})
  @severity = level
  @logger = options[:logger] if options[:logger]
  default_options = { verbose: false }
  @options = OpenStruct.new(default_options.merge(options))
end

Class Method Details

.build(type, level, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/tileup/logger.rb', line 9

def self.build type, level, options = {}
  case type
  when 'none' then TileUp::Loggers::None.new(level, options)
  when ::Logger then TileUp::Logger.new(level, options.merge(logger: type))
  else TileUp::Loggers::Console.new(level, options)
  end
end

.sym_to_severity(sym) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/tileup/logger.rb', line 17

def self.sym_to_severity(sym)
  severities =  {
    :debug   => ::Logger::DEBUG,
    :info    => ::Logger::INFO,
    :warn    => ::Logger::WARN,
    :error   => ::Logger::ERROR,
    :fatal   => ::Logger::FATAL
  }
  severity = severities[sym] || ::Logger::UNKNOWN
end

Instance Method Details

#error(message) ⇒ Object

log an error message



47
48
49
50
# File 'lib/tileup/logger.rb', line 47

def error(message)
  # note, we always log error messages
  add(:error, message)
end

#info(message) ⇒ Object

log a regular message



53
54
55
# File 'lib/tileup/logger.rb', line 53

def info(message)
  add(:info, message)
end

#levelObject



38
39
40
# File 'lib/tileup/logger.rb', line 38

def level
  @level
end

#level=(severity) ⇒ Object



42
43
44
# File 'lib/tileup/logger.rb', line 42

def level=(severity)
  logger.level = Logger.sym_to_severity(severity)
end

#verbose(message) ⇒ Object

log a verbose message



62
63
64
# File 'lib/tileup/logger.rb', line 62

def verbose(message)
  add(:info, message) if verbose?
end

#warn(message) ⇒ Object



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

def warn(message)
  add(:warn, message)
end