Class: Mnemosyne::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(allowed_log_levels) ⇒ Logger

Returns a new instance of Logger.



4
5
6
# File 'lib/mnemosyne/logger.rb', line 4

def initialize(allowed_log_levels)
    @allowed_log_levels = allowed_log_levels
end

Instance Method Details

#log(message, type = :info) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mnemosyne/logger.rb', line 8

def log(message, type=:info)
    return unless @allowed_log_levels.include?(type.to_s)

    time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
    case type
    when :info
        puts "[#{time}] [INF]:#{message}".colorize(:light_blue)
    when :success
        puts "[#{time}] [SUC]:#{message}".colorize(:green)
    when :error
        puts "[#{time}] [ERR]:#{message}".colorize(:red)
    when :warn
        puts "[#{time}] [WAR]:#{message}".colorize(:yellow)
    else
        puts "[#{type.upcase}] [#{time}] #{message}"
    end
end