push method
Push a single log entry. Buffered until auto-flush.
If entry.source is empty and defaultSource has been detected,
the entry's source is replaced with the auto-detected device string.
Implementation
void push(LogEntry entry) {
if (_disposed) return;
final effective = (entry.source.isEmpty && _defaultSource.isNotEmpty)
? LogEntry(
timestamp: entry.timestamp,
level: entry.level,
channel: entry.channel,
source: _defaultSource,
message: entry.message,
)
: entry;
_buffer.add(effective);
// OOM protection: discard oldest entries if buffer exceeds limit
if (_buffer.length > maxBufferSize) {
_buffer.removeRange(0, _buffer.length - maxBufferSize);
}
if (_buffer.length >= batchSize) {
flush();
} else {
_flushTimer ??= Timer(flushInterval, () {
_flushTimer = null;
flush();
});
}
}