Closed ibadb closed 2 years ago
Hi @ibadb, thanks for the question.
The pino
Logger constructor doesn't accept a third argument, so your first example can't work.
To set options.name
along with the pino options created by @elastic/ecs-pino-format
, you will need to merge the two sets of options together and pass them to pino()
. Something like this should work:
const pino = require('pino')
const ecsPinoFormat = require('@elastic/ecs-pino-format')
const log = pino({ name: 'myName', ...ecsPinoFormat() })
log.info('hi')
Running that results in:
% node play-pino.js
{"log.level":"info","@timestamp":"2022-06-02T21:18:51.563Z","process":{"pid":59472},"host":{"hostname":"pink.local"},"log":{"logger":"myName"},"ecs":{"version":"1.6.0"},"message":"hi"}
Please let me know if I've misunderstood your question.
I'm using the following code to return a pino logger instance. I want to log a custom 'name' attribute but I don't seem to get it to work. No errors. It just does not log the 'name' attribute. Everything else is working as expected. Is this the correct way to create a logger instance?
But if I change the code and remove the ECS function, it starts working as expected: