Problem
I have a logger with a custom level that is used as base to create the logger passed to Express.
import pino from 'pino';
import pinoHTTP from "pino-http";
export const logger = pino<"newLevel">({
customLevels: {
newLevel: 100,
},
})
const httpLogger = pinoHTTP({
logger: logger,
});
export default httpLogger;
However when I access the log property from the request it doesn't point to the right type of the logger being used (Logger<"newLevel">), instead it points to Logger<never> (from the base pino.d.ts AFAIK).
This causes TypeScript to complain when called the method req.log.newLevel(...) inside a controller.
app.get('/test', (req, res) => {
req.log.trace('trace log') // TypeScript doesn't complain!
req.log.newLevel('newLevel log')
// \__ Property 'newLevel' does not exist on type 'Logger<never>'.ts(2339)
res.status(200)
})
Question
How could I point TypeScript to look at the correct type of the logger inside the controllers when using custom levels?
Thanks in advance!
Problem
I have a logger with a custom level that is used as base to create the logger passed to Express.
However when I access the
logproperty from the request it doesn't point to the right type of the logger being used (Logger<"newLevel">), instead it points toLogger<never>(from the basepino.d.tsAFAIK).This causes TypeScript to complain when called the method
req.log.newLevel(...)inside a controller.Question
How could I point TypeScript to look at the correct type of the logger inside the controllers when using custom levels?
Thanks in advance!