Class: Capistrano::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/logger.rb

Overview

:nodoc:

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Logger

Returns a new instance of Logger.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capistrano/logger.rb', line 14

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

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



4
5
6
# File 'lib/capistrano/logger.rb', line 4

def device
  @device
end

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/capistrano/logger.rb', line 3

def level
  @level
end

Instance Method Details

#closeObject



27
28
29
# File 'lib/capistrano/logger.rb', line 27

def close
  device.close if @needs_close
end

#debug(message, line_prefix = nil) ⇒ Object



52
53
54
# File 'lib/capistrano/logger.rb', line 52

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

#debugx(message, line_prefix = nil) ⇒ Object



56
57
58
# File 'lib/capistrano/logger.rb', line 56

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

#important(message, line_prefix = nil) ⇒ Object



44
45
46
# File 'lib/capistrano/logger.rb', line 44

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

#info(message, line_prefix = nil) ⇒ Object



48
49
50
# File 'lib/capistrano/logger.rb', line 48

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

#log(level, message, line_prefix = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/capistrano/logger.rb', line 31

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

#trace(message, line_prefix = nil) ⇒ Object



60
61
62
# File 'lib/capistrano/logger.rb', line 60

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