All Articles/Logging

Configuring Batching, Flush Intervals, and Queue Size

Tune the SDK's batching behavior for your application's needs.


How Batching Works

The SDK does not send each log individually. Instead, it buffers logs and sends them in batches to reduce HTTP overhead. A batch is flushed when:

  1. The batch reaches batchSize logs (default: 25)
  2. The flushInterval timer fires (default: 5 seconds)
  3. You call flush() manually
  4. The application shuts down (SIGTERM/SIGINT handlers)

Configuration

JavaScript
Lognitor.init({
  apiKey: 'your-key',
  batchSize: 25,        // Logs per batch
  flushInterval: 5000,  // Flush every 5 seconds
  maxQueueSize: 1000,   // Maximum logs held in memory
  maxRetries: 3,        // Retry failed batches
});

Tuning for Your Use Case

High-throughput services — increase batchSize to 50–100 and maxQueueSize to 5000 to reduce HTTP requests.

Low-latency visibility — decrease flushInterval to 1000ms so logs appear in the dashboard faster.

Serverless functions — set batchSize: 1 or call await flush() at the end of each invocation, since the runtime may freeze between requests.

JavaScript
// Lambda / serverless pattern
export async function handler(event) {
  Lognitor.info('Processing event', { metadata: { eventId: event.id } });
  const result = await processEvent(event);
  await Lognitor.flush(); // Ensure logs are sent before freeze
  return result;
}

Queue Overflow

When maxQueueSize is reached, the oldest logs are dropped. Enable autoTruncate: true to shrink oversized payloads instead of dropping them entirely.