Module: PayPal::SDK::Core::Logging

Included in:
API::DataTypes::Base, Config, Util::HTTPHelper
Defined in:
lib/paypal-sdk/core/logging.rb

Overview

Include Logging module to provide logger functionality.

Configure logger

Logging.logger = Logger.new(STDERR)

Example

include Logger
logger.info "Debug message"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.loggerObject

Get or Create configured logger based on the default environment configuration


29
30
31
# File 'lib/paypal-sdk/core/logging.rb', line 29

def logger
  @logger ||= Logger.new(STDERR)
end

.logger=(logger) ⇒ Object

Set logger directly and clear the loggers cache.

Attributes

  • logger – Logger object

Example

Logging.logger = Logger.new(STDERR)

38
39
40
41
42
43
44
# File 'lib/paypal-sdk/core/logging.rb', line 38

def logger=(logger)
  @logger = logger
  if Config.config.mode.eql? 'live' and @logger.level == Logger::DEBUG
    @logger.warn "DEBUG log level not allowed in sandbox mode for security of confidential information. Changing log level to INFO..."
    @logger.level = Logger::INFO
  end
end

Instance Method Details

#log_event(message, &block) ⇒ Object


19
20
21
22
23
24
# File 'lib/paypal-sdk/core/logging.rb', line 19

def log_event(message, &block)
  start_time = Time.now
  block.call
ensure
  logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
end

#loggerObject

Get logger object


15
16
17
# File 'lib/paypal-sdk/core/logging.rb', line 15

def logger
  @logger ||= Logging.logger
end