Sha256: ec136453b3447b8649ab430b4c05fa8a790b9af035b1a56aadf30f089a66f5f5

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Diffend
  # Diffend logging
  class Logger
    # Low-level information, mostly for developers
    DEBUG = 0
    # Generic (useful) information about system operation
    INFO = 1
    # A warning
    WARN = 2
    # A handleable error condition
    ERROR = 3
    # An error that we are unable to handle that results in a program crash
    FATAL = 4
    # An unknown message that should always be logged
    UNKNOWN = 5

    # @param level [Integer] logging severity threshold
    def initialize(level = INFO)
      @level = level
    end

    # @param message [String]
    def debug(message)
      log(DEBUG, message)
    end

    # @param message [String]
    def info(message)
      log(INFO, message)
    end

    # @param message [String]
    def warn(message)
      log(WARN, message)
    end

    # @param message [String]
    def error(message)
      log(ERROR, message)
    end

    # @param message [String]
    def fatal(message)
      log(FATAL, message)
    end

    private

    # @param severity [Integer]
    # @param message [String]
    def log(severity, message)
      return if severity < @level

      case severity
      when INFO
        ::Bundler.ui.confirm(message)
      when WARN
        ::Bundler.ui.warn(message)
      when ERROR, FATAL
        ::Bundler.ui.error(message)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
diffend-0.2.54 lib/diffend/logger.rb
diffend-monitor-0.2.54 lib/diffend/logger.rb
diffend-0.2.53 lib/diffend/logger.rb
diffend-monitor-0.2.51 lib/diffend/logger.rb
diffend-0.2.51 lib/diffend/logger.rb
diffend-monitor-0.2.50 lib/diffend/logger.rb
diffend-0.2.50 lib/diffend/logger.rb
diffend-monitor-0.2.49 lib/diffend/logger.rb
diffend-0.2.49 lib/diffend/logger.rb
diffend-monitor-0.2.48 lib/diffend/logger.rb
diffend-0.2.48 lib/diffend/logger.rb
diffend-0.2.47 lib/diffend/logger.rb
diffend-monitor-0.2.46 lib/diffend/logger.rb
diffend-0.2.46 lib/diffend/logger.rb
diffend-0.2.45 lib/diffend/logger.rb
diffend-monitor-0.2.44 lib/diffend/logger.rb
diffend-0.2.44 lib/diffend/logger.rb
diffend-monitor-0.2.43 lib/diffend/logger.rb
diffend-0.2.43 lib/diffend/logger.rb
diffend-monitor-0.2.42 lib/diffend/logger.rb