pinojs/pino-elasticsearch

Is it possible to log by fields anh send logs to elasticsearch?

khaitranhq opened this issue · 4 comments

Hi,
I'm doing a project about log analysis using ELK Stack, I met problem that sending log from nodejs to elasticsearch, and I found pino-elasticsarch. However, I wonder that it is possible to use logger by filed (like status code, method, URL,...).
Thanks for any helps

maybe @delvedor can help

@lioaslan it’s not entirely clear to me what you are trying to achieve.
Can you add an example?

  • 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 personal 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
    }
});

So sorry about my poor English!!

Maybe that's stupid, Elasticsearch still get log but it don't log anything about that.