Class: TileUp::Logger
- Inherits:
-
Object
- Object
- TileUp::Logger
- Defined in:
- lib/tileup/logger.rb
Overview
Base logger class, subclass this, do not use directly.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#error(message) ⇒ Object
log an error message.
-
#info(message) ⇒ Object
log a regular message.
-
#initialize(level, options = {}) ⇒ Logger
constructor
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.
- #level ⇒ Object
- #level=(severity) ⇒ Object
-
#verbose(message) ⇒ Object
log a verbose message.
- #warn(message) ⇒ Object
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, = {}) @severity = level @logger = [:logger] if [:logger] = { verbose: false } @options = OpenStruct.new(.merge()) 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, = {} case type when 'none' then TileUp::Loggers::None.new(level, ) when ::Logger then TileUp::Logger.new(level, .merge(logger: type)) else TileUp::Loggers::Console.new(level, ) 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() # note, we always log error messages add(:error, ) end |
#info(message) ⇒ Object
log a regular message
53 54 55 |
# File 'lib/tileup/logger.rb', line 53 def info() add(:info, ) end |
#level ⇒ Object
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() add(:info, ) if verbose? end |
#warn(message) ⇒ Object
57 58 59 |
# File 'lib/tileup/logger.rb', line 57 def warn() add(:warn, ) end |