Sha256: 01da3b419198645905678d1034052b0bb724c22cf07b59a7e1932a5b14a12d5c

Contents?: true

Size: 1.28 KB

Versions: 73

Compression:

Stored size: 1.28 KB

Contents

module Capistrano
  class Logger #:nodoc:
    attr_accessor :level
    attr_reader   :device

    IMPORTANT = 0
    INFO      = 1
    DEBUG     = 2
    TRACE     = 3
    
    MAX_LEVEL = 3

    def initialize(options={})
      output = options[:output] || $stderr
      if output.respond_to?(:puts)
        @device = output
      else
        @device = File.open(output.to_str, "a")
        @needs_close = true
      end

      @options = options
      @level = 0
    end

    def close
      device.close if @needs_close
    end

    def log(level, message, line_prefix=nil)
      if level <= self.level
        indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)]
        (RUBY_VERSION >= "1.9" ? message.lines : message).each do |line|
          if line_prefix
            device.puts "#{indent} [#{line_prefix}] #{line.strip}\n"
          else
            device.puts "#{indent} #{line.strip}\n"
          end
        end
      end
    end

    def important(message, line_prefix=nil)
      log(IMPORTANT, message, line_prefix)
    end

    def info(message, line_prefix=nil)
      log(INFO, message, line_prefix)
    end

    def debug(message, line_prefix=nil)
      log(DEBUG, message, line_prefix)
    end

    def trace(message, line_prefix=nil)
      log(TRACE, message, line_prefix)
    end
  end
end

Version data entries

73 entries across 73 versions & 10 rubygems

Version Path
wulffeld-capistrano-2.5.8.3 lib/capistrano/logger.rb
capistrano-2.5.22 lib/capistrano/logger.rb
dan-capistrano-2.5.6 lib/capistrano/logger.rb
fotonauts-capistrano-2.5.2 lib/capistrano/logger.rb
mbailey-capistrano-2.5.5 lib/capistrano/logger.rb
mbailey-capistrano-2.5.6 lib/capistrano/logger.rb
mbailey-capistrano-2.5.7 lib/capistrano/logger.rb
sneakin-capistrano-2.5.5 lib/capistrano/logger.rb
thoughtbot-capistrano-2.5.5 lib/capistrano/logger.rb
thoughtbot-capistrano-2.5.6 lib/capistrano/logger.rb
wulffeld-capistrano-2.5.8.1 lib/capistrano/logger.rb
wulffeld-capistrano-2.5.8 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.27 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.26 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.25 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.24 lib/capistrano/logger.rb
capistrano-2.12.0 lib/capistrano/logger.rb
capistrano-2.11.2 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.23 lib/capistrano/logger.rb
HeSYINUvSBZfxqA-capistrano-2.5.22 lib/capistrano/logger.rb