`fastify.log.isLevelEnabled()` is missing from TypeScript types
matt-smarsh opened this issue · comments
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.26.2
Plugin version
No response
Node.js version
18.19.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
Pino exposes a function logger.isLevelEnabled()
which is available withing Fastify, but the TypeScript typing doesn't implement it. The type FastifyBaseLogger
should be updated to extend pino.Logger
in order to have the exact interface which matches what pino is exposing.
Conveniently, pino.Logger
also implements child()
so that can be removed from Fastify's types.
Inside types/logger.d.ts
:
export interface FastifyBaseLogger<CustomLevels extends string = never>
extends pino.Logger<CustomLevels> {}
Steps to Reproduce
With the following TypeScript:
import Fastify from "fastify"
const server = fastify({ logger: true })
console.log(`Trace enabled: `, server.log.isLevelEnabled("trace"))
Expected Behavior
The value of server.log
should expose the full Pino interface.
I would say it is a wontfix
because we need to support custom logger with minimal pino
interface.
Chasing it back and forth to provide complete pino
API and compatible minimal interface by default is not realistic currently.
As a workaround, you can supply the pino
interface to generic argument of TypeScript.
cc @fastify/typescript
That makes sense. Supporting custom loggers wasn't on my mind but perhaps it requires some more thought...
The generic could extend the BaseLogger, but default to Pino's full logger. That should support the current API contract. I feel like this should still merit consideration as the current TypeScript types are masking existing default functionality.
The generic could extend the BaseLogger, but default to Pino's full logger.
That sound do-able. We may try to see how it works.
I took a stab at it in the PR above ^