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:
- The batch reaches
batchSizelogs (default: 25) - The
flushIntervaltimer fires (default: 5 seconds) - You call
flush()manually - 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.