fastify / help

Need help with Fastify? File an Issue here.
https://www.fastify.io/
65 stars 8 forks source link

How can I use custom levers for pino logger with TS? #862

Open officefish opened 1 year ago

officefish commented 1 year ago

I have legal pino setup levels, but when I try to declare new function for logger fastify is error with regular register method.


import { buildApp, startApp, AppOptions, buildEmpty } from './src/app'

const envToLogger = {
    development: {
        transport: {
            target: 'pino-pretty',
            options: {
            translateTime: 'HH:MM:ss Z',
            ignore: 'pid,hostname',
            },
        },
        customLevels: {
            init: 35
        }
    },
    production: {
        customLevels: {
            init: 35
        }
    },
    test: false,
  }

const environment = 'development'

const options: AppOptions = {
    logger: envToLogger[environment] ?? true,
    pluginTimeout: 120_000
}

const start = async () => {
    const app = await buildApp(options)
    await startApp(app)
}

start()

My attempt to extend FastifyBaseLogger which breaks fastify instance methods:


declare module 'fastify' {
  interface FastifyBaseLogger {
    init: any
  }
}
mcollina commented 1 year ago

I don't know. I guess you would need to extend the types yourself.

Maybe @kibertoad could help.

kibertoad commented 1 year ago

I'll take a look