-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pino #124
Comments
Thanks Mick, that's super useful info. If we wanted to give pino a try, it'd be in a new The main question in my mind is whether we'd want to continue using the same kind of logger abstraction we've defined in node-common and make it possible to swap in a Does the default pino logging signature I'd be nice if we could choose pino as an alternative to winston to slot into new stacks, but I'm not sure whether aligning pino to an old abstraction will give us the best pino experience going forward. |
It's interesting none of the logging libs are very new. |
From the back of #115 (comment), I took a look at pino and found we should be able to drop it in with a few tweaks.
Things I looked at
defaultMeta
We use this to enrich all log entries emitted by winston.
Pino has a similar concept, through the
base
option.level
We tend to use
verbose
in localdev, which Pino doesn't support out of the box.We could move to
debug
, and mention it in migration docs.Or, use the
customLevels
notion to createverbose
.Error serialisation
Pino supports this out-of-the-box, with a caveat:
For it to be serialised, the
Error
instance needs to be either the full object we're passing (i.e.logger.error('error', new Error('boom'))
, or have a specific key in the object (i.e.logger.error('error', { err: new Error('boom') })
.The key is
err
by default and can be updated/augmented.omitPaths
This is supported through the
formatters.log
optionHow level is logged
By default, each level is associated an integer, which is used in log entries, so they look like:
I personally don't love this, and there's a way to change this through the
formatters.level
optionOTel instrumentation
We "need" this when we run in AWS to get traces to logs correlation, as AWS expects log entries to have a property that has the value
<trace-id>@<span-id>
, see example in MakerGraph.Luckily, such an instrumentation exists and has the same hook as the winston one.
Pretty printing
As mentioned in the link above, pino supports this out of the box.
Maybe I was holding it wrong, but it seemed some top-level config options needed to be set on the pino-pretty transport options to be applied, especially the
ignore
one.gave me this output on a client gig:
I haven't tried much more yet but will look into it.
Core logging API
By default, pino expects the meta/object/binding to be passed first, and the message second, i.e.
pino().info({ some: 'information', count: 10 }, 'this is the message')
Luckily, they advertise a way around this in the official docs, by leveraging the
hooks.logMethod
option.Keys
By default, messages have the
msg
key in log entries, and errors haveerr
.They're both configurable if we want to use whatever winston uses by default to not disrupt existing project.
See
messageKey
anderrorKey
.If we want, we can also make it that the input object is serialised in its own key to avoid potential conflicts, see
nestedKey
.silent
Some projects use the
TransportOptions.silent
option to shut the console up, like in test runs.It seems we can achieve the same either with:
enabled
option, orsilent
.The difference is that
level
is updateable at runtime, whereenabled
is not, see https://getpino.io/#/docs/api?id=event-39level-change39.Timestamp
By default, pino uses epoch-time seconds as the timestamp, but supports others through the
timestamp
option and provides built-in implementations with thestdTimeFunctions
exported object.Things missing
So far, the only missing thing I can think of is a built-in integration with the App Insights SDK, which only supports
console
,bunyan
, andwinston
by default.However, I'm sure we could come up with something of our own given the code is fairly simple.
The text was updated successfully, but these errors were encountered: