Class: Nanoc::CLI::Logger
- Inherits:
-
Object
- Object
- Nanoc::CLI::Logger
- Includes:
- Singleton
- Defined in:
- lib/nanoc/cli/logger.rb
Overview
Nanoc::CLI::Logger is a singleton class responsible for generating feedback in the terminal.
Constant Summary
- ACTION_COLORS =
Maps actions (
:create
,:update
,:identical
,:skip
and:delete
) onto their ANSI color codes. { :create => "\e[32m", # green :update => "\e[33m", # yellow :identical => '', # (nothing) :skip => '', # (nothing) :delete => "\e[31m" # red }
Instance Attribute Summary (collapse)
-
- (Symbol) level
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)
-
- (void) file(level, action, name, duration = nil)
Logs a file-related action.
-
- (Logger) initialize
constructor
A new instance of Logger.
-
- (void) log(level, message, io = $stdout)
Logs a message.
Constructor Details
- (Logger) initialize
Returns a new instance of Logger
30 31 32 |
# File 'lib/nanoc/cli/logger.rb', line 30 def initialize @level = :high end |
Instance Attribute Details
- (Symbol) level
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
- (void) file(level, action, name, duration = nil)
This method returns an undefined value.
Logs a file-related action.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nanoc/cli/logger.rb', line 43 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 |
- (void) log(level, message, io = $stdout)
This method returns an undefined value.
Logs a message.
65 66 67 68 69 70 71 |
# File 'lib/nanoc/cli/logger.rb', line 65 def log(level, , io = $stdout) # Don't log when logging is disabled return if @level == :off # Log when level permits it io.puts() if @level == :low || @level == level end |