lib/timber/log_devices/http.rb in timber-1.0.7 vs lib/timber/log_devices/http.rb in timber-1.0.8
- old
+ new
@@ -6,18 +6,19 @@
# The buffer and delivery strategy are very efficient and the log messages will be delivered in
# msgpack format.
#
# See {#initialize} for options and more details.
class HTTP
- API_URI = URI.parse("https://logs.timber.io/frames")
+ API_URI = URI.parse(ENV["TIMBER_INGESTION_URL"] || "https://logs.timber.io/frames")
CONTENT_TYPE = "application/x-timber-msgpack-frame-1".freeze
CONNECTION_HEADER = "keep-alive".freeze
USER_AGENT = "Timber Ruby Gem/#{Timber::VERSION}".freeze
HTTPS = Net::HTTP.new(API_URI.host, API_URI.port).tap do |https|
https.use_ssl = true
https.read_timeout = 30
https.ssl_timeout = 10
+ # Ruby 1.9.X doesn't have this setting.
if https.respond_to?(:keep_alive_timeout=)
https.keep_alive_timeout = 60
end
https.open_timeout = 10
end
@@ -62,10 +63,19 @@
overflow_handler: options[:buffer_overflow_handler]
)
@delivery_interval_thread = Thread.new do
loop do
sleep(options[:delivery_frequency_seconds] || DELIVERY_FREQUENCY_SECONDS)
+
+ @last_messages_overflow_count = 0
+ messages_overflown_count = @buffer.messages_overflown_count
+ if messages_overflown_count >= @last_messages_overflow_count
+ difference = messages_overflown_count - @last_messages_overflow_count
+ @last_messages_overflow_count = messages_overflown_count
+ logger.warn("Timber HTTP buffer has overflown #{difference} times")
+ end
+
buffer_for_delivery = @buffer.reserve
if buffer_for_delivery
deliver(buffer_for_delivery)
end
end
@@ -104,22 +114,28 @@
end
res = HTTPS.request(request)
code = res.code.to_i
if code < 200 || code >= 300
- Config.instance.logger.debug("Timber HTTP delivery failed - #{res.code}: #{res.body}")
- sleep((try_index + 1) * BACKOFF_RATE_SECONDS)
+ try = try_index + 1
+ logger.debug("Timber HTTP delivery failed, try #{try} - #{res.code}: #{res.body}")
+ sleep(try * BACKOFF_RATE_SECONDS)
else
@buffer.remove(body)
- Config.instance.logger.debug("Timber HTTP delivery successful - #{code}")
+ logger.debug("Timber HTTP delivery successful - #{code}")
+ logger.debug("Timber new buffer size - #{@buffer.total_bytesize}")
break # exit the loop
end
end
end
end
def authorization_payload
@authorization_payload ||= "Basic #{Base64.strict_encode64(@api_key).chomp}"
+ end
+
+ def logger
+ Config.instance.logger
end
end
end
end
\ No newline at end of file