lib/cucumber/chef/helpers/utility.rb in cucumber-chef-2.0.7 vs lib/cucumber/chef/helpers/utility.rb in cucumber-chef-2.1.0.rc.0

- old
+ new

@@ -1,10 +1,10 @@ ################################################################################ # # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com> # Author: Zachary Patten <zachary@jovelabs.com> -# Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd +# Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd # License: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,12 +21,32 @@ module Cucumber::Chef::Helpers::Utility ################################################################################ - def log(name, message) - STDOUT.puts("\033[34m >>> \033[1m#{name}\033[0m\033[34m #{message}\033[0m") + def log(message) + Cucumber::Chef.logger.info { message.gsub("$", "'") } + return if !(ENV['VERBOSE'] == "1") + + pattern = [ "\033[0m\033[36m", "\033[1m" ] + + result = [ " \033[0m\033[34m[\033[1mCC\033[0m\033[34m] \033[36m" ] + result << pattern.first + + sanity = message.split('').count{ |z| (z == "$") } + raise "You have a log message with an odd number of highlight markup characters! '#{message}' -> (sanity=#{sanity.inspect}) " if (sanity.modulo(2) != 0) + + chunks = message.split("$") + chunks.each_with_index do |chunk, index| + result << pattern[index.modulo(pattern.length)] + result << chunk + end + result << "\033[0m" + + STDOUT.puts(result.join) STDOUT.flush if STDOUT.respond_to?(:flush) + + true end ################################################################################ def generate_ip