Pino Pittfall(s)

Di.rk
1 min readFeb 11, 2021

--

Pino is a wonderful and fast logging API for Node.js and the Browser API.

One thing you should get used to is the first getting strange order for your logging statements. My first attempts looks like these rows.

logger.info('token NOT in cache, check with oauth server', token)

Because coming from console.log it was the natural way of creating log entries, but the output creates only lines with the text, not with the content of the token, what was intended.

Checking the API leads me to

logger.info(token, 'token NOT in cache, check with oauth server')

but now it always gives me only the token, that sometimes is an empty string.

Looking in greater detail at the API gives me the reason. He does not recognize the first parameter as an object, so he takes it what it was, as a string.

The solution is to wrap non objects into an object by simply surrounding it with brackets.

logger.info({ token }, 'token NOT in cache, check with oauth server')

Then you will get, what you expected, the value of the token and the message.

I hope I could save you some time.

Photo by Arnaud Mesureur on Unsplash

--

--

Di.rk
Di.rk

Written by Di.rk

Developer since the 80'th …

No responses yet