Sha256: 6ac49da0e02490e1260a60c7a809d707a99de0abc207f3e75a9c4237485d2bda

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

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 warning(text)
          $stdout.puts format_text("WARNING: #{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

4 entries across 4 versions & 1 rubygems

Version Path
capistrano-asg-rolling-0.5.1 lib/capistrano/asg/rolling/logger.rb
capistrano-asg-rolling-0.5.0 lib/capistrano/asg/rolling/logger.rb
capistrano-asg-rolling-0.4.1 lib/capistrano/asg/rolling/logger.rb
capistrano-asg-rolling-0.4.0 lib/capistrano/asg/rolling/logger.rb