Class: Capistrano::Logger
- Inherits:
-
Object
- Object
- Capistrano::Logger
- Defined in:
- lib/capistrano/logger.rb
Overview
:nodoc:
Constant Summary collapse
- IMPORTANT =
0
- INFO =
1
- DEBUG =
2
- TRACE =
3
- MAX_LEVEL =
3
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
- #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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/capistrano/logger.rb', line 13 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
26 27 28 |
# File 'lib/capistrano/logger.rb', line 26 def close device.close if @needs_close end |
#debug(message, line_prefix = nil) ⇒ Object
51 52 53 |
# File 'lib/capistrano/logger.rb', line 51 def debug(, line_prefix=nil) log(DEBUG, , line_prefix) end |
#important(message, line_prefix = nil) ⇒ Object
43 44 45 |
# File 'lib/capistrano/logger.rb', line 43 def important(, line_prefix=nil) log(IMPORTANT, , line_prefix) end |
#info(message, line_prefix = nil) ⇒ Object
47 48 49 |
# File 'lib/capistrano/logger.rb', line 47 def info(, line_prefix=nil) log(INFO, , line_prefix) end |
#log(level, message, line_prefix = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/capistrano/logger.rb', line 30 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
55 56 57 |
# File 'lib/capistrano/logger.rb', line 55 def trace(, line_prefix=nil) log(TRACE, , line_prefix) end |