class Rakali::Logger
Constants
- DEBUG
- ERROR
- INFO
- WARN
Attributes
Public Class Methods
Public: Create a new logger instance
level - (optional, integer) the log level
Returns nothing
# File lib/rakali/logger.rb, line 18 def initialize(level = INFO) @log_level = level end
Public Instance Methods
Public: Print a error message to stderr and immediately abort the process
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail (can be omitted)
Returns nothing
# File lib/rakali/logger.rb, line 68 def abort_with(topic, message = nil) error(topic, message) abort end
Public: Print a debug message to stdout
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
# File lib/rakali/logger.rb, line 28 def debug(topic, message = nil) $stdout.puts(message(topic, message)) if log_level <= DEBUG end
Public: Print a error message to stderr
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
# File lib/rakali/logger.rb, line 58 def error(topic, message = nil) $stderr.puts(message(topic, message).red) if log_level <= ERROR end
Public: Format the topic
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc.
Returns the formatted topic statement
# File lib/rakali/logger.rb, line 88 def formatted_topic(topic) "#{topic} ".rjust(20) end
Public: Print a message to stdout
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
# File lib/rakali/logger.rb, line 38 def info(topic, message = nil) $stdout.puts(message(topic, message)) if log_level <= INFO end
Public: Build a topic method
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns the formatted message
# File lib/rakali/logger.rb, line 79 def message(topic, message) formatted_topic(topic) + message.to_s end
Public: Print a message to stderr
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
# File lib/rakali/logger.rb, line 48 def warn(topic, message = nil) $stderr.puts(message(topic, message).yellow) if log_level <= WARN end