【发布时间】:2020-02-05 17:18:50
【问题描述】:
我想在我的 NestJs 应用程序中使用 Fastify 忽略或更改路由的 logLevel。
这就是我在 Fastify 应用程序中通常的做法。在这里,我将/health 路由logLevel 更改为error,这样它只会在运行状况出现错误时记录。
server.get('/health', { logLevel: 'error' }, async (request, reply) => {
if (mongoose.connection.readyState === 1) {
reply.code(200).send()
} else {
reply.code(500).send()
}
})
但这是我在 NestJs 中的健康控制器
@Get('health')
getHealth(): string {
return this.appService.getHealth()
}
还有 main.ts 文件。
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
logger: true
}),
)
我不想只记录健康路线而不是路线。
请在这方面提供帮助。
【问题讨论】:
-
你找到解决办法了吗?
-
@BinaryShrub 是的。我发布了对我们有用的解决方案。
标签: node.js logging nestjs fastify