module SgtnClient::Logging

Include Logging module to provide logger functionality.

Configure logger

Logging.logger = Logger.new(STDERR)

Example

include Logger
logger.info "Debug message"

Public Class Methods

logger() click to toggle source

Get or Create configured logger based on the default environment configuration

# File lib/sgtn-client/core/logging.rb, line 32
def logger
  @logger ||= Logger.new(STDERR)
end
logger=(logger) click to toggle source

Set logger directly and clear the loggers cache.

Attributes

  • logger – Logger object

Example

Logging.logger = Logger.new(STDERR)
# File lib/sgtn-client/core/logging.rb, line 41
def logger=(logger)
  @logger = logger
  if Config.config.mode.eql? 'live' and @logger.level == Logger::DEBUG
    @logger.warn "DEBUG log level not allowed in live mode for security of confidential information. Changing log level to INFO..."
    @logger.level = Logger::INFO
  end
end

Public Instance Methods

log_event(message, &block) click to toggle source
# File lib/sgtn-client/core/logging.rb, line 22
def log_event(message, &block)
  start_time = Time.now
  block.call
ensure
  logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
end
logger() click to toggle source

Get logger object

# File lib/sgtn-client/core/logging.rb, line 18
def logger
  @logger ||= Logging.logger
end