class SANStore::CLI::Logger
SANStore::CLI::Logger
is a singleton class responsible for generating feedback in the terminal.
Constants
- ACTION_COLORS
ANSI console codes (escape sequences) for highlighting particular log outputs.
Attributes
Whether to use color in log messages or not
Whether to use color in log messages or not
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).
Public Class Methods
# File lib/SANStore/cli/logger.rb, line 48 def initialize @level = :high @color = true end
Public Instance Methods
Logs a message.
level
-
The importance of this message. Can be :high or :low.
message
-
The message to be logged.
io
-
The IO instance to which the message will be written. Defaults to standard output.
# File lib/SANStore/cli/logger.rb, line 82 def log(level, message, io=$stdout) # Don't log when logging is disabled return if @level == :off # Log when level permits it io.puts(message) if (@level == :low or @level == level) end
Logs a messsage, using appropriate colours to highlight different levels.
level
-
The importance of this action. Can be :high or :low.
action
-
The kind of file action. Can be :create, :update or :identical.
message
-
The identifier of the item the action was performed on.
# File lib/SANStore/cli/logger.rb, line 62 def log_level(level, action, message) log( level, '%s%12s%s: %s' % [ color? ? ACTION_COLORS[action.to_sym] : '', action.to_s.capitalize, color? ? "\e[0m" : '', message.word_wrap(60).indent(15).lstrip ] ) end