Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Disable hostname in fastify logs with Pino

I’ve found that Pino offers a mechanism for removing this through an option called base but it seems that’s not available through the fastify logging configuration. What’s the best way to use the default fastify logger but remove the hostname from all log lines?

As a sample, here’s some output with the default fastify logger:

{"level":30,"time":1660583707685,"pid":17,"hostname":"goldsky-api-7cf949f758-zzpf2","msg":"Server listening at http://0.0.0.0:80"}

I’d like to remove hostname which is automatically injected into this log line.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

EDIT: the FastifyLoggerOptions don’t seem to provide fields for the pino base option which means if I try to pass that option, typescript compilation fails.

>Solution :

The logger option is forwarded to the fastify’s pino instance:

const fastify = require('fastify')({
  logger: {
    // pino options
    base: false,
  },
})
fastify.get('/', async (request, reply) => {
  return { hello: 'world' }
})
fastify.inject('/')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading