Class: OptionalLogger
Overview
An optional logger. If initialized with a logger instance, uses the logger otherwise doesn’t do anything. Basically trying to not require a particular logger class.
Instance Method Summary collapse
-
#debug(msg = nil, &blk) ⇒ Object
debug ….
-
#error(msg = nil, &blk) ⇒ Object
error ….
-
#info(msg = nil, &blk) ⇒ Object
info ….
-
#initialize(logger) ⇒ OptionalLogger
constructor
logger may be nil or a logger instance.
-
#warn(msg = nil, &blk) ⇒ Object
warn ….
Constructor Details
#initialize(logger) ⇒ OptionalLogger
logger may be nil or a logger instance
7 8 9 |
# File 'lib/tmdb/optional_logger.rb', line 7 def initialize(logger) @logger = logger end |
Instance Method Details
#debug(msg = nil, &blk) ⇒ Object
debug …
12 13 14 15 16 17 |
# File 'lib/tmdb/optional_logger.rb', line 12 def debug(msg=nil, &blk) unless @logger.nil? @logger.debug(msg) unless msg.nil? @logger.debug(blk.call) unless blk.nil? end end |
#error(msg = nil, &blk) ⇒ Object
error …
36 37 38 39 40 41 |
# File 'lib/tmdb/optional_logger.rb', line 36 def error(msg=nil, &blk) unless @logger.nil? @logger.error(msg) unless msg.nil? @logger.error(blk.call) unless blk.nil? end end |
#info(msg = nil, &blk) ⇒ Object
info …
20 21 22 23 24 25 |
# File 'lib/tmdb/optional_logger.rb', line 20 def info(msg=nil, &blk) unless @logger.nil? @logger.info(msg) unless msg.nil? @logger.info(blk.call) unless blk.nil? end end |
#warn(msg = nil, &blk) ⇒ Object
warn …
28 29 30 31 32 33 |
# File 'lib/tmdb/optional_logger.rb', line 28 def warn(msg=nil, &blk) unless @logger.nil? @logger.warn(msg) unless msg.nil? @logger.warn(blk.call) unless blk.nil? end end |