Class: Capistrano::Logger
- Inherits:
-
Object
- Object
- Capistrano::Logger
- 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
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #close ⇒ Object
- #debug(message, line_prefix = nil) ⇒ Object
- #debugx(message, line_prefix = nil) ⇒ Object
- #important(message, line_prefix = nil) ⇒ Object
- #info(message, line_prefix = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #log(level, message, line_prefix = nil) ⇒ Object
- #trace(message, line_prefix = nil) ⇒ Object
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(={}) output = [:output] || $stderr if output.respond_to?(:puts) @device = output else @device = File.open(output.to_str, "a") @needs_close = true end @options = @level = 0 end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
4 5 6 |
# File 'lib/capistrano/logger.rb', line 4 def device @device end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/capistrano/logger.rb', line 3 def level @level end |
Instance Method Details
#close ⇒ Object
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(, line_prefix=nil) log(DEBUG1, , line_prefix) end |
#debugx(message, line_prefix = nil) ⇒ Object
56 57 58 |
# File 'lib/capistrano/logger.rb', line 56 def debugx(, line_prefix=nil) log(DEBUG, , line_prefix) end |
#important(message, line_prefix = nil) ⇒ Object
44 45 46 |
# File 'lib/capistrano/logger.rb', line 44 def important(, line_prefix=nil) log(IMPORTANT, , line_prefix) end |
#info(message, line_prefix = nil) ⇒ Object
48 49 50 |
# File 'lib/capistrano/logger.rb', line 48 def info(, line_prefix=nil) log(INFO, , 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, , line_prefix=nil) if level <= self.level indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)] (RUBY_VERSION >= "1.9" ? .lines : ).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(, line_prefix=nil) log(TRACE, , line_prefix) end |