Module: RemindMe::Utils::Logger

Included in:
Runner, ResultPrinter
Defined in:
lib/remind_me/utils/logger.rb

Instance Method Summary collapse

Instance Method Details

#colorize(color_code, string) ⇒ Object



15
16
17
# File 'lib/remind_me/utils/logger.rb', line 15

def colorize(color_code, string)
  "\e[#{color_code}m#{string}\e[0m"
end

#green(string) ⇒ Object



23
24
25
# File 'lib/remind_me/utils/logger.rb', line 23

def green(string)
  colorize(32, string)
end

#log_error(msg) ⇒ Object



11
12
13
# File 'lib/remind_me/utils/logger.rb', line 11

def log_error(msg)
  rails_being_used? ? log_with_rails(red(msg), :error) : puts(red(msg))
end

#log_info(msg) ⇒ Object



7
8
9
# File 'lib/remind_me/utils/logger.rb', line 7

def log_info(msg)
  rails_being_used? ? log_with_rails(green(msg), :info) : puts(green(msg))
end

#log_with_rails(msg, severity) ⇒ Object



31
32
33
# File 'lib/remind_me/utils/logger.rb', line 31

def log_with_rails(msg, severity)
  Rails.logger.send(severity, msg)
end

#rails_being_used?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/remind_me/utils/logger.rb', line 27

def rails_being_used?
  defined?(Rails)
end

#red(string) ⇒ Object



19
20
21
# File 'lib/remind_me/utils/logger.rb', line 19

def red(string)
  colorize(31, string)
end