Sha256: 5e810a5abb6633f5a5324a9dda297096b244b5a354cb887ef56b25a359766fa8

Contents?: true

Size: 932 Bytes

Versions: 3

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

module Capistrano
  module ASG
    module Rolling
      # Logging support.
      class Logger
        def initialize(verbose: false)
          @verbose = verbose
        end

        def info(text)
          $stdout.puts format_text(text)
        end

        def error(text)
          $stderr.puts format_text(text, color: :red) # rubocop:disable Style/StderrPuts
        end

        def verbose(text)
          info(text) if @verbose
        end

        private

        def format_text(text, color: nil)
          text = colorize_text(text, color) if color
          text.gsub(/\*\*(.+?)\*\*/, bold_text('\\1'))
        end

        def bold_text(text)
          "\e[1m#{text}\e[22m"
        end

        def colorize_text(text, color)
          _color.colorize(text, color)
        end

        def _color
          @_color ||= SSHKit::Color.new($stdout)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
capistrano-asg-rolling-0.3.0 lib/capistrano/asg/rolling/logger.rb
capistrano-asg-rolling-0.2.1 lib/capistrano/asg/rolling/logger.rb
capistrano-asg-rolling-0.2.0 lib/capistrano/asg/rolling/logger.rb