Sha256: bac439bf7f642395d7e03b61ade573f93ed2ef05b282d6332e421b2c5f2026c1

Contents?: true

Size: 962 Bytes

Versions: 18

Compression:

Stored size: 962 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(msg=nil, &blk)
    unless @logger.nil?
      @logger.debug(msg) unless msg.nil?
      @logger.debug(blk.call) unless blk.nil?
    end
  end

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

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

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

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
royw-dvdprofiler_collection-0.1.1 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.1.2 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.1.3 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.1.4 lib/dvdprofiler_collection/optional_logger.rb
royw-dvdprofiler_collection-0.1.5 lib/dvdprofiler_collection/optional_logger.rb
royw-imdb-0.1.1 lib/imdb/optional_logger.rb
royw-imdb-0.1.2 lib/imdb/optional_logger.rb
royw-imdb-0.1.3 lib/imdb/optional_logger.rb
royw-imdb-0.1.4 lib/imdb/optional_logger.rb
royw-imdb-0.1.5 lib/imdb/optional_logger.rb
royw-imdb-0.1.6 lib/imdb/optional_logger.rb
royw-tmdb-0.1.1 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.2 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.3 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.4 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.5 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.6 lib/tmdb/optional_logger.rb
royw-tmdb-0.1.7 lib/tmdb/optional_logger.rb