Sha256: 130498505a15f2767c17dca8220f9d610953f7a3763fe6c7a7129327f03e850d

Contents?: true

Size: 780 Bytes

Versions: 3

Compression:

Stored size: 780 Bytes

Contents

require_relative '../util/custom_logger'
require_relative '../util/void_logger'
require_relative '../util/custom_formatter'

module MangoPay

  # Provides logger objects.
  class LogProvider

    ENABLE_LOGGING = false
    ENABLE_HTTP_LOGGING = false

    class << self

      def provide(context)
        if needs_http_logger(context) && ENABLE_HTTP_LOGGING\
          || (!needs_http_logger(context) && ENABLE_LOGGING)
          logger = CustomLogger.new(STDOUT)
          logger.progname = context.name
          logger.formatter = CustomFormatter.new
          logger
        else
          VoidLogger.new
        end
      end

      private

      def needs_http_logger(context)
        context.name =~ /HttpClient/ || context.name =~ /Jsonifier/
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mangopay-v4-4.1.0 lib/mangopay/common/log_provider.rb
mangopay-v4-4.0.2 lib/mangopay/common/log_provider.rb
mangopay-v4-4.0.1 lib/mangopay/common/log_provider.rb