Class: Nanoc3::CLI::Logger

Included Modules

Singleton

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

Attributes

Instance Attributes

color [RW] public

Whether to use color in log messages or not.

Also known as: color?
level [RW] public

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

Constants

ACTION_COLORS
{ :create => "\e[1m" + "\e[32m", # bold + green :update => "\e[1m" + "\e[33m", # bold + yellow :identical => "\e[1m", # bold :skip => "\e[1m" # bold }

Constructor Summary

public initialize
[View source]


29
30
31
32
# File 'lib/nanoc3/cli/logger.rb', line 29

def initialize
  @level = :high
  @color = true
end

Public Visibility

Public Instance Method Summary

#file(level, action, identifier, duration = nil)

Logs a file-related action.

#log(level, s, io = $stdout)

Logs a message.

Public Instance Method Details

file

public file(level, action, identifier, duration = nil)

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.
[View source]


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nanoc3/cli/logger.rb', line 42

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

public log(level, s, io = $stdout)

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.
[View source]


63
64
65
66
67
68
69
# File 'lib/nanoc3/cli/logger.rb', line 63

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
Generated on Sunday, August 09 2009 at 01:43:13 PM by YARD 0.2.3.2 (ruby-1.8.7).