Skip to content

Fastify plugin

This is very similar to the express extension and provides the same features but in a slightly different way. Rather than passing the options (for custom format) when creating your logger instance, you pass another options object when registering the plugin.


npm i leekslazylogger-fastify


// set up logger with options
const FastifyLogger = require('leekslazylogger-fastify');
const log = new FastifyLogger({
    name: 'My fastify server', // regular options such as custom types
    custom: {
        http: {
            title: 'info',
            prefix: 'http'

// require fastify
const fastify = require('fastify')();

// use logger plugin
// OR
fastify.register(log.fastify, {
    format: '{method} &7{path}', // optional
    type: 'http'

// other plugins and router

// start server




FastifyLogger takes the same options as normal:

const log = new FastifyLogger({
    name: 'My fastify server'

And the fastify plugin also takes options:

fastify.register(log.fastify, {
    format: '{method} &7{path}',
    type: 'console'


The default format is: {method} {status-colour}{status} &7{path} {time-colour}({time})

The string can include colour codes.


The available placeholders for setting your own format are:

  • {method}: GET/POST etc
  • {protocol}: HTTP or HTTPS
  • {route}: fastify route name (eg: /users/:id)
  • {path}: Full path (no query)
  • {status-colour} / {status-color}: green/orange/blue/red colour code based on status code (to prefix status)
  • {status}: status code (200, 301, 404 etc)
  • {time-colour} / {time-color}: light green/yellow/red colour code based on time (to prefix time)
  • {time}: time in ms for request to be completed

Last update: February 25, 2021