Method: Logtail::LogDevices::HTTP#write

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

#write(msg) ⇒ Object

Write a new log line message to the buffer, and flush asynchronously if the message queue is full. We flush asynchronously because the maximum message batch size is constricted by the Logtail API. The actual application limit is a multiple of this. Hence the ‘@request_queue`.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/logtail/log_devices/http.rb', line 91

def write(msg)
  @msg_queue.enq(msg)

  # Lazily start flush threads to ensure threads are alive after forking processes.
  # If the threads are started during instantiation they will not be copied when
  # the current process is forked. This is the case with various web servers,
  # such as phusion passenger.
  ensure_flush_threads_are_started

  if @msg_queue.full?
    Logtail::Config.instance.debug { "Flushing HTTP buffer via write" }
    flush_async
  end
  true
end