Class: GALogger

Inherits:
Object
  • Object
show all
Defined in:
lib/ga_logger.rb

Overview

Author:

  • Vittorio Monaco

Class Method Summary collapse

Class Method Details

.log(message, type = :Default, padding = ' ### ') ⇒ Object

Note:

depending on the message type, a different color will be used to print the message on the console

Logs a message on the console

Parameters:

  • message (String)

    a string to log

  • type (Symbol) (defaults to: :Default)

    specifies the type of message. This can be :Error, :Warning, :Success or :Default

  • padding (String) (defaults to: ' ### ')

    the padding to put before and after the message



15
16
17
# File 'lib/ga_logger.rb', line 15

def self.log(message, type = :Default, padding = ' ### ')
  puts sequenceForType(type) + padding + message + padding + sequenceForType(:Default)
end

.sequenceForType(type) ⇒ Object

Returns the character code to print with the right color given a message type

Parameters:

  • type (Symbol)

    the message type. This can be :Error, :Warning, :Success or :Default



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ga_logger.rb', line 22

def self.sequenceForType(type)
  case type
  when :Success
    return "\033[32m"
  when :Error
    return "\033[31m"
  when :Warning
    return "\033[33m"
  else
    return "\033[0m"
  end
end