Class: Nanoc3::CLI::Logger
- Inherits:
-
Object
- Object
- Nanoc3::CLI::Logger
- Includes:
- Singleton
- Defined in:
- lib/nanoc3/cli/logger.rb
Overview
Nanoc3::CLI::Logger is a singleton class responsible for generating feedback in the terminal.
Constant Summary
- ACTION_COLORS =
Maps actions (
:create,:update,:identicaland:skip) onto their ANSI color codes. { :create => "\e[1m" + "\e[32m", # bold + green :update => "\e[1m" + "\e[33m", # bold + yellow :identical => "\e[1m", # bold :skip => "\e[1m" # bold }
Instance Attribute Summary (collapse)
-
- (Boolean) color
(also: #color?)
True if color should be used, false otherwise.
-
- (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, identifier, 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
A new instance of Logger
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nanoc3/cli/logger.rb', line 33 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 |
Instance Attribute Details
- (Boolean) color Also known as: color?
True if color should be used, false otherwise
30 31 32 |
# File 'lib/nanoc3/cli/logger.rb', line 30 def color @color end |
- (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).
27 28 29 |
# File 'lib/nanoc3/cli/logger.rb', line 27 def level @level end |
Instance Method Details
- (void) file(level, action, identifier, duration = nil)
This method returns an undefined value.
Logs a file-related action.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nanoc3/cli/logger.rb', line 54 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 |
- (void) log(level, message, io = $stdout)
This method returns an undefined value.
Logs a message.
76 77 78 79 80 81 82 |
# File 'lib/nanoc3/cli/logger.rb', line 76 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 or @level == level) end |