lib/semantic_logger/appender/http.rb in semantic_logger-3.0.0 vs lib/semantic_logger/appender/http.rb in semantic_logger-3.0.1
- old
+ new
@@ -19,11 +19,11 @@
# appender.filter = Proc.new { |log| log.message !~ /(health_check|Not logged in)/}
#
# SemanticLogger.add_appender(appender)
class SemanticLogger::Appender::Http < SemanticLogger::Appender::Base
attr_accessor :username, :application, :host, :compress, :header
- attr_reader :http, :url, :server, :port, :request_uri, :ssl_options
+ attr_reader :http, :url, :server, :port, :path, :ssl_options
# Create HTTP(S) log appender
#
# Parameters:
# url: [String]
@@ -88,16 +88,18 @@
@header['Content-Encoding'] = 'gzip' if @compress
uri = URI.parse(@url)
(@ssl_options ||= {})[:use_ssl] = true if uri.scheme == 'https'
- @server = uri.host
- @port = uri.port
- @username = uri.user if !@username && uri.user
- @password = uri.password if !@password && uri.password
- @request_uri = uri.request_uri
+ @server = uri.host
+ raise(ArgumentError, "Invalid format for :url: #{@url.inspect}. Should be similar to: 'http://hostname:port/path'") unless @url
+ @port = uri.port
+ @username = uri.user if !@username && uri.user
+ @password = uri.password if !@password && uri.password
+ @path = uri.request_uri
+
reopen
# Pass on the level and custom formatter if supplied
super(level, filter, &block)
end
@@ -130,23 +132,23 @@
gz.close
str.string
end
# HTTP Post
- def post(body, request_uri = nil)
- request = Net::HTTP::Post.new(request_uri || @request_uri, @header)
+ def post(body, request_uri = path)
+ request = Net::HTTP::Post.new(request_uri, @header)
process_request(request, body)
end
# HTTP Put
- def put(body, request_uri = nil)
- request = Net::HTTP::Put.new(request_uri || @request_uri, @header)
+ def put(body, request_uri = path)
+ request = Net::HTTP::Put.new(request_uri, @header)
process_request(request, body)
end
# HTTP Delete
- def delete(request_uri = nil)
- request = Net::HTTP::Delete.new(request_uri || @request_uri, @header)
+ def delete(request_uri = path)
+ request = Net::HTTP::Delete.new(request_uri, @header)
process_request(request)
end
# Process HTTP Request
def process_request(request, body = nil)