Is it possible to log by fields anh send logs to elasticsearch?
khaitranhq opened this issue · 4 comments
khaitranhq commented
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
delvedor commented
@lioaslan it’s not entirely clear to me what you are trying to achieve.
Can you add an example?
khaitranhq commented
- I'm building server for a website use
hapi
andhapi-pino
for logging. - I want to analyze log (about status code, route, timestamp) for some personal purpose. I use
elasticsearch
andkibana
to do it - Between
hapi-pino
andElasticsearch
, 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!!
khaitranhq commented
Maybe that's stupid, Elasticsearch still get log but it don't log anything about that.