Class: TileUp::TileUpLogger

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

Overview

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

Direct Known Subclasses

ConsoleLogger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, options) ⇒ TileUpLogger

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



23
24
25
26
27
28
29
# File 'lib/tileup/logger.rb', line 23

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

Class Method Details

.sym_to_severity(sym) ⇒ Object



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

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



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

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

#info(message) ⇒ Object

log a regular message



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

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

#levelObject



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

def level
  @level
end

#level=(severity) ⇒ Object



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

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

#verbose(message) ⇒ Object

log a verbose message



55
56
57
# File 'lib/tileup/logger.rb', line 55

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

#warn(message) ⇒ Object



50
51
52
# File 'lib/tileup/logger.rb', line 50

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