Class: Nanoc::CLI::Logger Private
- Inherits:
-
Object
- Object
- Nanoc::CLI::Logger
- 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.
Maps actions (‘:create`, `:update`, `:identical`, `:cached`, `:skip` and `:delete`) onto their ANSI color codes.
{ create: "\e[32m", # green update: "\e[33m", # yellow identical: '', # (nothing) cached: '', # (nothing) skip: '', # (nothing) delete: "\e[31m", # red }.freeze
Instance Attribute Summary collapse
-
#level ⇒ Symbol
private
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).
Instance Method Summary collapse
-
#file(level, action, name, duration = nil) ⇒ void
private
Logs a file-related action.
-
#initialize ⇒ Logger
constructor
private
A new instance of Logger.
-
#log(level, message, io = $stdout) ⇒ void
private
Logs a message.
Constructor Details
#initialize ⇒ Logger
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.
30 31 32 33 |
# File 'lib/nanoc/cli/logger.rb', line 30 def initialize @level = :high @mutex = Mutex.new end |
Instance Attribute Details
#level ⇒ Symbol
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).
28 29 30 |
# File 'lib/nanoc/cli/logger.rb', line 28 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.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nanoc/cli/logger.rb', line 44 def file(level, action, name, duration = nil) log( level, format( '%s%12s%s %s%s', ACTION_COLORS[action.to_sym], action, "\e[0m", duration.nil? ? '' : format('[%2.2fs] ', duration), name, ), ) end |
#log(level, message, io = $stdout) ⇒ 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.
67 68 69 70 71 72 73 74 |
# File 'lib/nanoc/cli/logger.rb', line 67 def log(level, , io = $stdout) return if @level == :off return if @level != :low && @level != level @mutex.synchronize do io.puts() end end |