lib/nanoc3/cli/logger.rb in nanoc3-3.1.9 vs lib/nanoc3/cli/logger.rb in nanoc3-3.2.0a1
- old
+ new
@@ -6,53 +6,48 @@
# Nanoc3::CLI::Logger is a singleton class responsible for generating
# feedback in the terminal.
class Logger
- # Maps actions (`:create`, `:update`, `:identical` and `:skip`) onto their
- # ANSI color codes.
ACTION_COLORS = {
:create => "\e[1m" + "\e[32m", # bold + green
:update => "\e[1m" + "\e[33m", # bold + yellow
:identical => "\e[1m", # bold
:skip => "\e[1m" # bold
}
include Singleton
- # Returns the log level, which can be :high, :low or :off (which will log
- # all messages, only high-priority messages, or no messages at 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).
- #
- # @return [Symbol] The log level
attr_accessor :level
- # @return [Boolean] True if color should be used, false otherwise
+ # Whether to use color in log messages or not
attr_accessor :color
alias_method :color?, :color
def initialize
@level = :high
- @color = $stdout.tty?
+ @color = true
# Try enabling color support on Windows
begin
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~/mswin|mingw/
rescue LoadError
- @color = false
+ warn 'The win32console gem is not available. Install it to enable color support on Windows.'
end
end
# Logs a file-related action.
#
- # @param [:high, :low] level The importance of this action
+ # +level+:: The importance of this action. Can be :high or :low.
#
- # @param [:create, :update, :identical] action The kind of file action
+ # +action+:: The kind of file action. Can be :create, :update or
+ # :identical.
#
- # @param [String] name The name of the file the action was performed on
- #
- # @return [void]
+ # +identifier+:: The identifier of the item the action was performed on.
def file(level, action, identifier, duration=nil)
log(
level,
'%s%12s%s %s%s' % [
color? ? ACTION_COLORS[action.to_sym] : '',
@@ -64,22 +59,21 @@
)
end
# Logs a message.
#
- # @param [:high, :low] level The importance of this message
+ # +level+:: The importance of this message. Can be :high or :low.
#
- # @param [String] message The message to be logged
+ # +s+:: The message to be logged.
#
- # @param [#puts] io The stream to which the message should be written
- #
- # @return [void]
- def log(level, message, io=$stdout)
+ # +io+:: The IO instance to which the message will be written. Defaults to
+ # standard output.
+ def log(level, s, io=$stdout)
# Don't log when logging is disabled
return if @level == :off
# Log when level permits it
- io.puts(message) if (@level == :low or @level == level)
+ io.puts(s) if (@level == :low or @level == level)
end
end
end