Pino's forrmater can't apply to elasticsearch
Closed this issue · 4 comments
Hi,
I'm learning about hapi and elasticsearch. When I try to map IP to location with Pino, I have some problem.
I use formatter for create new field (https://getpino.io/#/docs/api?id=log).
When I use hapi-pino
to print formatted log on console, it worked ok.
However, I send formatted log to elasticsearch, I don't see new field when I access routes of hapi
(new field still appear when sever init)
Code
"use strict";
const Pino = require('pino');
const HapiPino = require('hapi-pino');
const PinoElasticsearch = require('pino-elasticsearch');
const { LOG_TYPE } = require('../../config.log');
module.exports = {
name: "app-pino",
async register(server) {
if (process.env.NODE_ENV !== 'test') {
const { LOG_HOST, LOG_PORT, LOG_USERNAME, LOG_PASSWORD, LOG_INDEX } = process.env;
const streamToElastic = PinoElasticsearch({
index: LOG_INDEX,
consistency: 'one',
node: `http://${LOG_USERNAME}:${LOG_PASSWORD}@${LOG_HOST}:${LOG_PORT}`,
'bulk-size': 200,
'es-version': 7
});
const formatters = {
log(object){
return {
...object,
newField: "Leo
};
}
};
const logger =
LOG_TYPE === 'elasticsearch'
? Pino({ formatters }, streamToElastic)
: Pino({ formatters, prettyPrint: process.env.NODE_ENV !== 'production' });
await server.register({
plugin: HapiPino,
options: {
formatters,
logPayload: true,
redact: {
paths: ['req.headers', 'payload.user.password', 'payload.file'],
remove: true
},
instance: logger,
mergeHapiLogData: true
}
});
}
}
};
Log on elasticsearch
Thanks so much
@delvedor Hope you reply me soon, thanks
@delvedor I need fixing this issue to complete my assignment :( so I hope you reply as soon as possible.
Thanks so much
Hello, I'm currently on vacation and I don't have time to look into this.
It would be great to have a small example to reproduce the issue.
The code you have posted it's not enough, you should add the Elasticsearch mappings as well as an example of what you are expecting.