Class: Smplkit::LoggerRegistrationBuffer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/buffers.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Thread-safe batch buffer for logger discovery.

Instance Method Summary collapse

Constructor Details

#initializeLoggerRegistrationBuffer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LoggerRegistrationBuffer.



219
220
221
222
223
# File 'lib/smplkit/buffers.rb', line 219

def initialize
  @seen = {}
  @pending = []
  @lock = Mutex.new
end

Instance Method Details

#add(source) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/smplkit/buffers.rb', line 225

def add(source)
  @lock.synchronize do
    next if @seen.key?(source.name)

    @seen[source.name] = source.resolved_level
    item = { "id" => source.name, "resolved_level" => source.resolved_level&.to_s }
    item["level"] = source.level&.to_s if source.level
    item["service"] = source.service if source.service
    item["environment"] = source.environment if source.environment
    @pending << item
  end
end

#drainObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



238
239
240
241
242
243
244
# File 'lib/smplkit/buffers.rb', line 238

def drain
  @lock.synchronize do
    batch = @pending
    @pending = []
    batch
  end
end

#pending_countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



246
247
248
# File 'lib/smplkit/buffers.rb', line 246

def pending_count
  @lock.synchronize { @pending.length }
end