Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add options for limits to logging

  • Loading branch information...
commit cf0ebebb0627b40c85c67e0e377291e96bdfad51 1 parent e5107fd
Greg Weber authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/net-http-spy.rb
View
8 lib/net-http-spy.rb
@@ -15,9 +15,11 @@ class << self
def initialize(*args, &block)
self.class.http_logger_options ||= {}
- defaults = {:body => false, :trace => false, :verbose => false}
+ defaults = {:body => false, :trace => false, :verbose => false, :limit => -1}
self.class.http_logger_options = (self.class.http_logger_options == :default) ? defaults : self.class.http_logger_options
@logger_options = defaults.merge(self.class.http_logger_options)
+ @params_limit = @logger_options[:params_limit] || @logger_options[:limit]
+ @body_limit = @logger_options[:body_limit] || @logger_options[:limit]
self.class.http_logger.info "CONNECT: #{args.inspect}" if !@logger_options[:verbose]
@@ -35,9 +37,9 @@ def request(*args, &block)
result = old_request(*args, &block)
unless started? || @logger_options[:verbose]
- self.class.http_logger.info "PARAMS #{CGI.parse(args[0].body).inspect} " if args[0].body && req != 'CONNECT'
+ self.class.http_logger.info "PARAMS #{CGI.parse(args[0].body).inspect[0..@params_limit]} " if args[0].body && req != 'CONNECT'
self.class.http_logger.info "TRACE: #{caller.reverse}" if @logger_options[:trace]
- self.class.http_logger.info "BODY: #{ @logger_options[:body] ? result.body : result.class.name}"
+ self.class.http_logger.info "BODY: #{(@logger_options[:body] ? result.body : result.class.name)[0..@body_limit]}"
end
result
end
Please sign in to comment.
Something went wrong with that request. Please try again.