Class: Capistrano::LogWithAwesome

Inherits:
Logger
  • Object
show all
Defined in:
lib/capistrano/log_with_awesome.rb,
lib/capistrano/log_with_awesome/version.rb

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.init(config) ⇒ Object

replaces the built in Capistrano logger with awesome



6
7
8
9
10
11
# File 'lib/capistrano/log_with_awesome.rb', line 6

def self.init(config)
  @config = config
  level = @config.logger.level
  @config.logger = new
  @config.logger.level = level
end

.log_with_awesome(message) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/capistrano/log_with_awesome.rb', line 13

def self.log_with_awesome(message)
  @buffer ||= []
  @buffer << message
  @config.set :message, message
  @config.set :full_log, @buffer.join("\n")
  @config.silently_trigger(:log_message)
end

Instance Method Details

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

Log and do awesome things I wish there was a nicer way to do this. Hax on device.puts, maybe?



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/capistrano/log_with_awesome.rb', line 23

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