diff options
author | elijah <elijah@riseup.net> | 2013-02-27 23:53:10 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-02-27 23:53:10 -0800 |
commit | 56a42b9858058473a07f254c49d0bb00dadce2d9 (patch) | |
tree | 834f6371fddc17ccf7c4806a08f298d07f9b2ddf /lib/leap_cli/log.rb | |
parent | 006744350595f89818e23ee77d096adf9b47207b (diff) |
improve logging: set exit code on puppet error, better puppet error handling, better handling of multi-line puppet log entries.
Diffstat (limited to 'lib/leap_cli/log.rb')
-rw-r--r-- | lib/leap_cli/log.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/leap_cli/log.rb b/lib/leap_cli/log.rb index fb43d7b..4d5e4da 100644 --- a/lib/leap_cli/log.rb +++ b/lib/leap_cli/log.rb @@ -78,7 +78,7 @@ module LeapCli if title prefix_options = case title when :error then ['error', :red, :bold] - when :warning then ['warning', :yellow, :bold] + when :warning then ['warning:', :yellow, :bold] when :info then ['info', :cyan, :bold] when :updated then ['updated', :cyan, :bold] when :updating then ['updating', :cyan, :bold] @@ -126,6 +126,7 @@ module LeapCli # # Add a raw log entry, without any modifications (other than indent). # Content to be logged is yielded by the block. + # Block may be either a string or array of strings. # # if mode == :stdout, output is sent to STDOUT. # if mode == :log, output is sent to log file, if present. @@ -134,16 +135,18 @@ module LeapCli # NOTE: print message (using 'print' produces better results than 'puts' when multiple threads are logging) if mode == :log if LeapCli.log_output_stream - message = yield - if message + messages = [yield].compact.flatten + if messages.any? timestamp = Time.now.strftime("%b %d %H:%M:%S") - LeapCli.log_output_stream.print("#{timestamp} #{message}\n") + messages.each do |message| + LeapCli.log_output_stream.print("#{timestamp} #{message}\n") + end LeapCli.log_output_stream.flush end end elsif mode == :stdout - message = yield - if message + messages = [yield].compact.flatten + if messages.any? indent ||= LeapCli.indent_level indent_str = "" indent_str += " " * indent.to_i @@ -152,7 +155,9 @@ module LeapCli else indent_str += ' = ' end - STDOUT.print("#{indent_str}#{message}\n") + messages.each do |message| + STDOUT.print("#{indent_str}#{message}\n") + end end end end |