Sha256: abdade35a2b46b31ebb3d39a4a729dc668649b4888686878cacae5a0ae61b48b

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

require 'logger'

require 'aptible/cli/version'
require 'aptible/cli/agent'
require 'aptible/cli/error'
require 'aptible/cli/formatter'
require 'aptible/cli/renderer'
require 'aptible/cli/resource_formatter'

module Aptible
  module CLI
    class LogFormatter
      include Term::ANSIColor

      def call(severity, _, _, msg)
        color = case severity
                when 'DEBUG'
                  :no_color
                when 'INFO'
                  :green
                when 'WARN'
                  :yellow
                when 'ERROR', 'FATAL'
                  :red
                else
                  :no_color
                end

        "#{public_send(color, msg)}\n"
      end

      def no_color(msg)
        msg
      end
    end

    def self.logger
      @logger ||= Logger.new($stderr).tap do |l|
        l.formatter = LogFormatter.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aptible-cli-0.15.1 lib/aptible/cli.rb
aptible-cli-0.15.0 lib/aptible/cli.rb