Method: Logtail::LogDevices::HTTP#initialize

Defined in:
lib/logtail/log_devices/http.rb

#initialize(source_token, options = {}) ⇒ HTTP

Instantiates a new HTTP log device that can be passed to Logtail::Logger#initialize.

The class maintains a buffer which is flushed in batches to the Logtail API. 2 options control when the flush happens, ‘:batch_byte_size` and `:flush_interval`. If either of these are surpassed, the buffer will be flushed.

By default, the buffer will apply back pressure when the rate of log messages exceeds the maximum delivery rate. If you don’t want to sacrifice app performance in this case you can drop the log messages instead by passing a DroppingSizedQueue via the ‘:request_queue` option.

Examples:

Basic usage

Logtail::Logger.new(Logtail::LogDevices::HTTP.new("my_logtail_source_token"))

Apply back pressure instead of dropping messages

http_log_device = Logtail::LogDevices::HTTP.new("my_logtail_source_token", request_queue: SizedQueue.new(25))
Logtail::Logger.new(http_log_device)

Parameters:

  • source_token (String)

    The API key provided to you after you add your application to [Logtail](logtail.com).

  • options (Hash) (defaults to: {})

    the options to create a HTTP log device with.

  • attributes (Hash)

    a customizable set of options



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/logtail/log_devices/http.rb', line 72

def initialize(source_token, options = {})
  @source_token = source_token || raise(ArgumentError.new("The source_token parameter cannot be blank"))
  @logtail_host = options[:logtail_host] || ENV['LOGTAIL_HOST'] || LOGTAIL_HOST
  @logtail_port = options[:logtail_port] || ENV['LOGTAIL_PORT'] || LOGTAIL_PORT
  @logtail_scheme = options[:logtail_scheme] || ENV['LOGTAIL_SCHEME'] || LOGTAIL_SCHEME
  @batch_size = options[:batch_size] || 1_000
  @flush_continuously = options[:flush_continuously] != false
  @flush_interval = options[:flush_interval] || 2 # 2 seconds
  @requests_per_conn = options[:requests_per_conn] || 2_500
  @msg_queue = FlushableDroppingSizedQueue.new(@batch_size)
  @request_queue = options[:request_queue] || FlushableDroppingSizedQueue.new(25)
  @successive_error_count = 0
  @requests_in_flight = 0
end