Sha256: ce5ac324e7bd79c0e150767d4e89418fe9752b8887abf083e1fed405036decb0

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

# Null logger class. This is essentially the same as sending data down the
# `/dev/null` black hole.
#
# @example Basic Usage
#
#   logger = NullLogger.new
#   Rails.logger = logger
#
#
# @example Basic Pattern Usage
#   class SomeService
#     def initialize(options = {})
#       @logger = options[:logger] || NullLogger.new
#     end
#
#     def perform
#       @logger.debug -> { "do some work here" }
#       # .. ..
#       @logger.info -> { "finished working" }
#     end
#   end
#
#   service = SomeService.new(logger: Logger.new(STDOUT))
#   service.perform
#
#   silent = SomeService.new(logger: NullLogger.new
#   silent.perform
#
class NullLogger
  # @param _args Anything that we want to ignore
  # @return [nil]
  def unknown(*_args)
    nil
  end

  # @param _args Anything that we want to ignore
  # @return [nil]
  def fatal(*_args)
    nil
  end

  # @return [FALSE]
  def fatal?
    false
  end

  # @param _args Anything that we want to ignore
  # @return [nil]
  def error(*_args)
    nil
  end

  # @return [FALSE]
  def error?
    false
  end

  # @param _args Anything that we want to ignore
  # @return [nil]
  def warn(*_args)
    nil
  end

  # @return [FALSE]
  def warn?
    false
  end

  # @param _args Anything that we want to ignore
  # @return [nil]
  def info(*_args)
    nil
  end

  # @return [FALSE]
  def info?
    false
  end

  # @param _args Anything that we want to ignore
  # @return [nil]
  def debug(*_args)
    nil
  end

  # @return [FALSE]
  def debug?
    false
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
null-logger-0.1.7 lib/null_logger.rb
null-logger-0.1.6 lib/null_logger.rb