Sha256: 105f09fbfaadaedcd162d205bf1b5aa6bb993933bede735f6085e6d7ad723538

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'colorize'

module Reviewer
  # Clean formatter for logging to $stdout
  class StandardOutFormatter < ::Logger::Formatter
    # Overrides ::Logger::Formatter `call` to more present output more concisely
    # @param _severity [Logger::Severity] Unused - Logger severity for etnry
    # @param _time [DateTime] Unused - Timestamp for entry
    # @param _progname [String] Unused - Name of the current program for entry
    # @param message [String] The string to print to $stdout
    #
    # @return [type] [description]
    def call(_severity, _time, _progname, message)
      "#{message}\n"
    end
  end

  # Logger for $stdout
  class Logger < ::Logger
    SUCCESS = 'Success'
    FAILURE = 'Failure ·'
    PROMPT  = '$'

    def initialize(formatter = StandardOutFormatter.new)
      super($stdout)
      @formatter = formatter
    end

    def running(tool)
      info "\n#{tool.name}".bold + ' · '.light_black + tool.description
    end

    def command(cmd)
      info "\nReviewer ran this command:"
      info cmd.to_s.light_black
    end

    def rerunning(tool, cmd)
      info "\nRe-running #{tool.name} verbosely:"
      info cmd.to_s.light_black
    end

    def success(elapsed_time)
      info SUCCESS.green.bold + " (#{elapsed_time.round(3)}s)".green
    end

    def failure(message)
      error "#{FAILURE} #{message}".red.bold
    end

    def total_time(elapsed_time)
      info "\n➤ Total Time: #{elapsed_time.round(3)}s\n"
    end

    def guidance(summary, details)
      info "\n#{summary}" if summary
      info details.to_s.light_black if details
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewer-0.1.3 lib/reviewer/logger.rb