Sha256: cc789f5db57c6e0280d50825a229e5e8f92710592fde94979b1b5675c575fefe

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

module Backup
  class Logger
    class Console
      class Options
        ##
        # Disables all console output.
        #
        # This may also be set on the command line using +--quiet+.
        #
        # If +--no-quiet+ is used on the command line, console output
        # will be enabled and any setting here will be ignored.
        #
        # @param [Boolean, nil]
        # @return [Boolean, nil] Default: +false+
        attr_reader :quiet

        def initialize
          @quiet = false
        end

        def enabled?
          !quiet
        end

        def quiet=(val)
          @quiet = val unless quiet.nil?
        end
      end

      COLORS = {
        info: "\e[32m%s\e[0m", # green
        warn: "\e[33m%s\e[0m", # yellow
        error: "\e[31m%s\e[0m" # red
      }

      def initialize(_options = nil)
        $stdout.sync = $stderr.sync = true
      end

      def log(message)
        io = message.level == :info ? $stdout : $stderr
        lines = message.formatted_lines
        lines.map! { |line| COLORS[message.level] % line } if io.tty?
        io.puts lines
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
backup-5.0.0.beta.3 lib/backup/logger/console.rb
backedup-5.0.0.beta.5 lib/backup/logger/console.rb
backedup-5.0.0.beta.4 lib/backup/logger/console.rb
backedup-5.0.0.beta.3 lib/backup/logger/console.rb
ext_backup-5.0.0.beta.2.1 lib/backup/logger/console.rb
ext_backup-5.0.0.beta.2.ext.0.1.2 lib/backup/logger/console.rb
ext_backup-5.0.0.beta.2.ext.0.1.1 lib/backup/logger/console.rb
ext_backup-5.0.0.beta.2.ext.0.1.0 lib/backup/logger/console.rb
backup-5.0.0.beta.2 lib/backup/logger/console.rb
backup-5.0.0.beta.1 lib/backup/logger/console.rb
backup-bouchard-4.4.4 lib/backup/logger/console.rb
backup-bouchard-4.4.2 lib/backup/logger/console.rb
backup-bouchard-4.4.1 lib/backup/logger/console.rb