Parent

Methods

Included Modules

Class/Module Index [+]

Quicksearch

Nanoc3::CLI::Logger

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

Constants

ACTION_COLORS

Attributes

color[RW]

Whether to use color in log messages or not

color?[RW]

Whether to use color in log messages or not

level[RW]

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

Public Class Methods

new() click to toggle source
# File lib/nanoc3/cli/logger.rb, line 28
def initialize
  @level = :high
  @color = $stdout.tty?

  # Try enabling color support on Windows
  begin
    require 'Win32/Console/ANSI' if RUBY_PLATFORM =~/mswin|mingw/
  rescue LoadError
    @color = false
  end
end

Public Instance Methods

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

Logs a file-related action.

level

The importance of this action. Can be :high or :low.

action

The kind of file action. Can be :create, :update or :identical.

identifier

The identifier of the item the action was performed on.

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

Logs a message.

level

The importance of this message. Can be :high or :low.

s

The message to be logged.

io

The IO instance to which the message will be written. Defaults to standard output.

# File lib/nanoc3/cli/logger.rb, line 69
def log(level, s, io=$stdout)
  # Don't log when logging is disabled
  return if @level == :off

  # Log when level permits it
  io.puts(s) if (@level == :low or @level == level)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.