class Sentry::LogEventBuffer
@!visibility private
This is used internally by the ‘Sentry::Client`.
LogEventBuffer buffers log events and sends them to Sentry in a single envelope.
def add_event(event)
def add_event(event) raise ArgumentError, "expected a LogEvent, got #{event.class}" unless event.is_a?(LogEvent) @mutex.synchronize do @pending_events << event send_events if size >= @max_events end self end
def empty?
def empty? @pending_events.empty? end
def flush
def flush @mutex.synchronize do return if empty? log_debug("[LogEventBuffer] flushing #{size} log events") send_events end log_debug("[LogEventBuffer] flushed #{size} log events") self end
def initialize(configuration, client)
def initialize(configuration, client) super(configuration.sdk_logger, FLUSH_INTERVAL) @client = client @pending_events = [] @max_events = configuration.max_log_events || DEFAULT_MAX_EVENTS @mutex = Mutex.new log_debug("[Logging] Initialized buffer with max_events=#{@max_events}, flush_interval=#{FLUSH_INTERVAL}s") end
def send_events
def send_events @client.send_logs(@pending_events) @pending_events.clear end
def size
def size @pending_events.size end
def start
def start ensure_thread self end