Handle stream events for debugging
masterThe stream handler returned by pinoElastic() is an EventEmitter. You can listen to specific events to debug why logs might not be appearing in Elasticsearch.
| Event | Callback Signature | Description |
|---|---|---|
unknown | (line: string, error: string) => void | Received event is unparsable (JSON.parse failed). Often happens if using pino-pretty on the stream. |
insertError | (error: Error & { document: Record<string, any> }) => void | Bulk insert failed (records dropped). Use this to check for schema/mapping mismatches. |
insert | (stats: Record<string, any>) => void | Successful insert performed. |
error | (error: Error) => void | General Elasticsearch client failure. |
const pinoElastic = require('pino-elasticsearch');
const streamToElastic = pinoElastic({
index: 'an-index',
node: 'http://localhost:9200',
esVersion: 7,
flushBytes: 1000
})
streamToElastic.on('<event>', (error) => console.log(event));