Module: WscSdk::Loggable

Included in:
Endpoint, Model
Defined in:
lib/wsc_sdk/modules/loggable.rb

Overview

A module that adds access to a logger.

This will check to see if a Client object is available, and use its logger otherwise it checks for an endpoint and will use its logger, as a last ditch it will build a new plain old logger that logs to STDOUT.

There is a logger attribute accessor, so you can overwrite the logger with your own.

Instance Method Summary collapse

Instance Method Details

#loggerLogger

Returns an instance of a logger.

Returns:

  • (Logger)

    The assigned logger.



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

def logger
  if @logger.nil?
    if self.respond_to?(:client)
      @logger = self.client.logger
    elsif self.respond_to?(:endpoint)
      @logger = self.endpoint.logger
    end

    @logger ||= Logger.new(STDOUT)
  end

  @logger
end

#logger=(_logger) ⇒ Object

Sets the instance of logger.

Parameters:

  • _logger (Logger)

    The logger instance to use for logging.



40
41
42
# File 'lib/wsc_sdk/modules/loggable.rb', line 40

def logger= _logger
  @logger = _logger
end