1
  • I'm building server for a website use hapi and hapi-pino for logging.
  • I want to analyze log (about status code, route, timestamp) for some business purpose. I use elasticsearch and kibana to do it
  • Between hapi-pino and Elasticsearch, I try to use pino-elasticsearch to send log. However, it didn't work, elasticsearch didn't get anything This is my code for registering hapi-pino:
const streamToElastic = PinoElasticsearch({
    index: 'api',
    type: 'log',
    consistency: 'one',
    node: 'http://elastic:changeme@localhost:9200',
    'es-version': 6,
    'bulk-size': 200,
    ecs: true
});

await server.register({
    plugin: HapiPino,
    options: {
        logPayload: true,
        prettyPrint: process.env.NODE_ENV !== 'production',
        redact: {
            paths: ['req.headers', 'payload.user.password', 'payload.file'],
            remove: true
        },
        stream: streamToElastic
    }
});

Thanks for any helps and sorry about my poor English!

Leo Aslan
  • 451
  • 1
  • 8
  • 20
  • Don't know if this helps but for es 7 I was having the issue of trying to connect to elastic before it being ready and that marked the connection as dead. Make sure that your elasticsearch is up and running before trying to connect from your node app. – António Quadrado Oct 29 '21 at 15:04

0 Answers0