Sha256: 5e5e8641d89518e7236a77208680a64265a5125764917294e2d7e154f8066b23

Contents?: true

Size: 862 Bytes

Versions: 6

Compression:

Stored size: 862 Bytes

Contents

module ThreeScaleToolbox
  class ProxyLogger < BasicObject
    def initialize(subject)
      @subject = subject
    end

    def method_missing(name, *args)
      # Correct delegation https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
      start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
      result = @subject.public_send(name, *args)
    ensure
      end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start_time
      ::Kernel.warn "-- call #{name} args |#{args.inspect[0..2000]}| response |#{result.inspect[0..2000]}| - (#{end_time}s)"
      result
    end
    ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)

    def public_send(name, *args)
      method_missing(name, *args)
    end

    def respond_to_missing?(method_name, include_private = false)
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/proxy_logger.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/proxy_logger.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/proxy_logger.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/proxy_logger.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/proxy_logger.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/proxy_logger.rb