diff options
author | elijah <elijah@riseup.net> | 2012-11-27 01:40:01 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-11-27 01:40:01 -0800 |
commit | b5bf2fe3874f9ce97b36dc37b17ce66270260f03 (patch) | |
tree | 7af8ccce2a3862545f04d91a60fcd8f3104e1342 /vendor/supply_drop/lib | |
parent | 051675c61937f184c555bac3af07be182f0c6acd (diff) | |
download | leap_cli-b5bf2fe3874f9ce97b36dc37b17ce66270260f03.tar.gz leap_cli-b5bf2fe3874f9ce97b36dc37b17ce66270260f03.tar.bz2 |
improved logging all around.
Diffstat (limited to 'vendor/supply_drop/lib')
-rw-r--r-- | vendor/supply_drop/lib/supply_drop/writer/colorful_streaming.rb | 67 | ||||
-rw-r--r-- | vendor/supply_drop/lib/supply_drop/writer/streaming.rb | 53 |
2 files changed, 68 insertions, 52 deletions
diff --git a/vendor/supply_drop/lib/supply_drop/writer/colorful_streaming.rb b/vendor/supply_drop/lib/supply_drop/writer/colorful_streaming.rb new file mode 100644 index 0000000..6abe90d --- /dev/null +++ b/vendor/supply_drop/lib/supply_drop/writer/colorful_streaming.rb @@ -0,0 +1,67 @@ +begin + require 'paint' +rescue +end + +module SupplyDrop + module Writer + class Streaming + def initialize(logger) + @mode = Capistrano::Logger::DEBUG + @logger = logger + end + + def collect_output(host, data) + if data =~ /^(notice|err|warning):/ + @mode = $1 + + # make deprecation warnings like notices + if data =~ /^warning: .*is deprecated.*$/ + @mode = 'notice' + end + + # force the printing of 'finished catalog run' if there have not been any errors + if @mode == 'notice' && !@error_encountered && data =~ /Finished catalog run/ + @mode = 'forced_notice' + elsif @mode == 'err' + @error_encountered = true + end + end + + # log each line, colorizing the hostname + data.lines.each do |line| + if line =~ /\w/ + @logger.log log_level, line.sub(/\n$/,''), colorize(host) + end + end + end + + def log_level + case @mode + when 'err' then Capistrano::Logger::IMPORTANT + when 'warning' then Capistrano::Logger::INFO + when 'notice' then Capistrano::Logger::DEBUG + else Capistrano::Logger::IMPORTANT + end + end + + def colorize(str) + if defined? Paint + color = case @mode + when 'err' then :red + when 'warning' then :yellow + when 'notice' then :cyan + when 'forced_notice' then :cyan + else :clear + end + Paint[str, color, :bold] + else + str + end + end + + def all_output_collected + end + end + end +end diff --git a/vendor/supply_drop/lib/supply_drop/writer/streaming.rb b/vendor/supply_drop/lib/supply_drop/writer/streaming.rb index 6abe90d..e180ec8 100644 --- a/vendor/supply_drop/lib/supply_drop/writer/streaming.rb +++ b/vendor/supply_drop/lib/supply_drop/writer/streaming.rb @@ -1,63 +1,12 @@ -begin - require 'paint' -rescue -end - module SupplyDrop module Writer class Streaming def initialize(logger) - @mode = Capistrano::Logger::DEBUG @logger = logger end def collect_output(host, data) - if data =~ /^(notice|err|warning):/ - @mode = $1 - - # make deprecation warnings like notices - if data =~ /^warning: .*is deprecated.*$/ - @mode = 'notice' - end - - # force the printing of 'finished catalog run' if there have not been any errors - if @mode == 'notice' && !@error_encountered && data =~ /Finished catalog run/ - @mode = 'forced_notice' - elsif @mode == 'err' - @error_encountered = true - end - end - - # log each line, colorizing the hostname - data.lines.each do |line| - if line =~ /\w/ - @logger.log log_level, line.sub(/\n$/,''), colorize(host) - end - end - end - - def log_level - case @mode - when 'err' then Capistrano::Logger::IMPORTANT - when 'warning' then Capistrano::Logger::INFO - when 'notice' then Capistrano::Logger::DEBUG - else Capistrano::Logger::IMPORTANT - end - end - - def colorize(str) - if defined? Paint - color = case @mode - when 'err' then :red - when 'warning' then :yellow - when 'notice' then :cyan - when 'forced_notice' then :cyan - else :clear - end - Paint[str, color, :bold] - else - str - end + @logger.debug data, host end def all_output_collected |