Class: Nanoc::CLI::Logger Private

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/nanoc/cli/logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Constant Summary collapse

ACTION_COLORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  create: [:green],
  update: [:yellow],
  identical: [],
  cached: [],
  skip: [],
  delete: [:red],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Logger.



28
29
30
31
# File 'lib/nanoc/cli/logger.rb', line 28

def initialize
  @level = :high
  @mutex = Mutex.new
end

Instance Attribute Details

#levelSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Symbol)

    The log level



26
27
28
# File 'lib/nanoc/cli/logger.rb', line 26

def level
  @level
end

Instance Method Details

#file(level, action, name, duration = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs a file-related action.

Parameters:

  • level (:high, :low)

    The importance of this action

  • action (:create, :update, :identical, :cached, :skip, :delete)

    The kind of file action

  • name (String)

    The name of the file the action was performed on



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

def file(level, action, name, duration = nil)
  colorizer = Nanoc::CLI::ANSIStringColorizer.new($stdout)
  colored_action = colorizer.c(action.to_s, *ACTION_COLORS[action.to_sym])

  message = format(
    '%12s  %s%s',
    colored_action,
    duration.nil? ? '' : format('[%2.2fs]  ', duration),
    name,
  )

  log(level, message)
end

#log(level, message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Logs a message.

Parameters:

  • level (:high, :low)

    The importance of this message

  • message (String)

    The message to be logged



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

def log(level, message)
  return if @level == :off
  return if @level != :low && @level != level

  @mutex.synchronize do
    puts(message)
  end
end