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"}

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

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' }

Leave a Reply