Parent

Methods

Included Modules

Class/Module Index [+]

Quicksearch

Nanoc::CLI::Logger

Nanoc::CLI::Logger is a singleton class responsible for generating feedback in the terminal.

Constants

ACTION_COLORS

Maps actions (`:create`, `:update`, `:identical`, `:skip` and `:delete`) onto their ANSI color codes.

Attributes

level[RW]

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, respectively).

@return [Symbol] The log level

Public Class Methods

new() click to toggle source
# File lib/nanoc/cli/logger.rb, line 29
def initialize
  @level = :high
end

Public Instance Methods

file(level, action, name, duration=nil) click to toggle source

Logs a file-related action.

@param [:high, :low] level The importance of this action

@param [:create, :update, :identical, :skip, :delete] action The kind of file action

@param [String] name The name of the file the action was performed on

@return [void]

# File lib/nanoc/cli/logger.rb, line 42
def file(level, action, name, duration=nil)
  log(
    level,
    '%s%12s%s  %s%s' % [
      ACTION_COLORS[action.to_sym],
      action,
      "\e[0m",
      duration.nil? ? '' : "[%2.2fs]  " % [ duration ],
      name
    ]
  )
end
log(level, message, io=$stdout) click to toggle source

Logs a message.

@param [:high, :low] level The importance of this message

@param [String] message The message to be logged

@param [puts] io The stream to which the message should be written

@return [void]

# File lib/nanoc/cli/logger.rb, line 64
def log(level, message, 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)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.