lib/nanoc/cli/logger.rb in nanoc-2.1.6 vs lib/nanoc/cli/logger.rb in nanoc-2.2

- old
+ new

@@ -5,25 +5,31 @@ # Nanoc::CLI::Logger is a singleton class responsible for generating # feedback in the terminal. class Logger ACTION_COLORS = { - :create => "\e[1m" + "\e[32m", # bold + green - :update => "\e[1m" + "\e[33m", # bold + yellow - :identical => "\e[1m", # bold - :skip => "\e[1m" # bold + :create => "\e[1m" + "\e[32m", # bold + green + :update => "\e[1m" + "\e[33m", # bold + yellow + :identical => "\e[1m", # bold + :skip => "\e[1m", # bold + :'not written' => "\e[1m" # bold } include Singleton - # The log leve, which can be :high, :low or :off (which will log all + # The log level, which can be :high, :low or :off (which will log all # messages, only high-priority messages, or no messages at all, # respectively). attr_accessor :level + # Whether to use color in log messages or not + attr_accessor :color + alias_method :color?, :color + def initialize # :nodoc: @level = :high + @color = true end # Logs a file-related action. # # +level+:: The importance of this action. Can be :high or :low. @@ -34,12 +40,12 @@ # +path+:: The path to the file the action was performed on. def file(level, action, path, duration=nil) log( level, '%s%12s%s %s%s' % [ - ACTION_COLORS[action.to_sym], + color? ? ACTION_COLORS[action.to_sym] : '', action, - "\e[0m", + color? ? "\e[0m" : '', duration.nil? ? '' : "[%2.2fs] " % [ duration ], path ] ) end