Sha256: b275c7471eaf0b8a814bc4cac5136ebf8b734071d99fc79382a8adeeef265e09

Contents?: true

Size: 644 Bytes

Versions: 9

Compression:

Stored size: 644 Bytes

Contents

# 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.
class OptionalLogger
  # logger may be nil or a logger instance
  def initialize(logger)
    @logger = logger
  end

  # debug {...}
  def debug(&blk)
    @logger.debug(blk.call) unless @logger.nil?
  end

  # info {...}
  def info(&blk)
    @logger.info(blk.call) unless @logger.nil?
  end

  # warn {...}
  def warn(&blk)
    @logger.warn(blk.call) unless @logger.nil?
  end

  # error {...}
  def error(&blk)
    @logger.error(blk.call) unless @logger.nil?
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
royw-dvdprofiler_collection-0.0.2 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.0.3 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.1.0 lib/dvdprofiler_collection/optional_logger.rb
royw-imdb-0.0.20 lib/imdb/optional_logger.rb
royw-imdb-0.0.21 lib/imdb/optional_logger.rb
royw-imdb-0.1.0 lib/imdb/optional_logger.rb
royw-tmdb-0.0.1 lib/tmdb/optional_logger.rb
royw-tmdb-0.0.2 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.0 lib/tmdb/optional_logger.rb