Class: SiteMapper::Logger

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

Overview

Handles logging

Defined Under Namespace

Modules: NilLogger, SystemOutLogger

Class Method Summary collapse

Class Method Details

.err_log(err_msg) ⇒ Object

Parameters:

  • err_msg (String)

    to be logged



31
32
33
34
# File 'lib/site_mapper/logger.rb', line 31

def self.err_log(err_msg)
  @@log ||= use_logger_type(:default)
  @@log.err_log(err_msg)
end

.log(msg) ⇒ Object

Parameters:

  • msg (String)

    to be logged



25
26
27
28
# File 'lib/site_mapper/logger.rb', line 25

def self.log(msg)
  @@log ||= use_logger_type(:default)
  @@log.log(msg)
end

.use_logger(logger) ⇒ Object

Parameters:

  • logger (Class, #log, #err_log)

    a logger class



19
20
21
22
# File 'lib/site_mapper/logger.rb', line 19

def self.use_logger(logger)
  fail 'Logger already set' if defined?(@@log)
  @@log = logger
end

.use_logger_type(type) ⇒ Object

Parameters:

  • type (Symbol)

    of logger class to be used



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/site_mapper/logger.rb', line 5

def self.use_logger_type(type)
  fail 'Logger already set' if defined?(@@log)
  @@log = case type.to_s
  when 'nil', 'default'
    NilLogger
  when 'system'
    SystemOutLogger
  else
    fail ArgumentError, "Unknown logger type: '#{type}'"
  end
  @@log
end