Class: SoraGeocoding::Logger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sora_geocoding/logger.rb

Overview

Logger

Constant Summary collapse

LOG_LEVEL =
{
  debug: ::Logger::DEBUG,
  info: ::Logger::INFO,
  warn: ::Logger::WARN,
  error: ::Logger::ERROR,
  fatal: ::Logger::FATAL
}.freeze

Instance Method Summary collapse

Instance Method Details

#add(level, message) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sora_geocoding/logger.rb', line 35

def add(level, message)
  return unless log_message_at_level?(level)

  case level
  when ::Logger::DEBUG, ::Logger::INFO
    puts message
  when ::Logger::WARN
    warn message
  when ::Logger::ERROR
    raise message
  when ::Logger::FATAL
    raise message
  end
end

#log(level, message) ⇒ Object

Raises:

  • (StandardError)


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

def log(level, message)
  raise StandardError, 'SoraGeocoding tried to log a message with an invalid log level.' unless valid_level?(level)

  if respond_to?(:add)
    add(LOG_LEVEL[level], message)
  else
    raise SoraGeocoding::ConfigurationError, 'Please specify valid logger for SoraGeocoding. ' \
                                             'Logger specified must respond to `add(level, message)`.'
  end
  nil
end