Sha256: f6fba34758b38a2a1b1d3fe5153b554c813fa0bb35c8a86756e1c93512f02bca

Contents?: true

Size: 1.15 KB

Versions: 33

Compression:

Stored size: 1.15 KB

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 TtyLogFormatter
      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

    class PlainLogFormatter
      def call(_, _, _, msg)
        "#{msg}\n"
      end
    end

    def self.logger
      formatter_klass = if $stderr.tty?
                          TtyLogFormatter
                        else
                          PlainLogFormatter
                        end

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
aptible-cli-0.24.2 lib/aptible/cli.rb
aptible-cli-0.24.1 lib/aptible/cli.rb
aptible-cli-0.24.0 lib/aptible/cli.rb
aptible-cli-0.23.0 lib/aptible/cli.rb
aptible-cli-0.22.0 lib/aptible/cli.rb
aptible-cli-0.21.0 lib/aptible/cli.rb
aptible-cli-0.20.0 lib/aptible/cli.rb
aptible-cli-0.19.9 lib/aptible/cli.rb
aptible-cli-0.19.7 lib/aptible/cli.rb
aptible-cli-0.19.6 lib/aptible/cli.rb
aptible-cli-0.19.4 lib/aptible/cli.rb
aptible-cli-0.19.3 lib/aptible/cli.rb
aptible-cli-0.19.2 lib/aptible/cli.rb
aptible-cli-0.19.1 lib/aptible/cli.rb
aptible-cli-0.19.0 lib/aptible/cli.rb
aptible-cli-0.18.3 lib/aptible/cli.rb
aptible-cli-0.18.2 lib/aptible/cli.rb
aptible-cli-0.18.1 lib/aptible/cli.rb
aptible-cli-0.18.0 lib/aptible/cli.rb
aptible-cli-0.17.2 lib/aptible/cli.rb