pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

Undefined variables are not logged #618

Closed jcald1 closed 5 years ago

jcald1 commented 5 years ago

If you execute:

log.info({ msg: 'test', msgUndefined: undefined })

pino logs:

{"level":30,"time":1553633517657,"pid":1,"hostname":"a8455c8d7d8b","msg":"test","v":1}

the properties with values of undefined are not logged. These should be logged, or at the very least the option to log them should be configurable.

pino version: 5.11.3

mcollina commented 5 years ago

JSON does not include undefined values. pino is a json logger, and as such we cannot include them.

jcald1 commented 5 years ago

@mcollina, would it make sense to optionally map them to null based on the pino configuration?

jsumners commented 5 years ago

null is a value in JavaScript whereas undefined is equivalent to the property not being present at all. So I wouldn’t think it makes sense to remap undefined to null.

jcald1 commented 5 years ago

@jsumners , that is correct, but from a practical point of view, it is often useful in logging to know that a variable is undefined. I wonder if it would make sense to have some reserved property name that can be used to convey information that normally gets dropped in a conversion to JSON. Or to allow the user to have more control using more configuration options.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.