小编Anw*_*lik的帖子

如何在 NestJs 中使用 Fastify 忽略特定路由日志记录?

我想使用 Fastify 忽略或更改 NestJs 应用程序中路由的 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()
    }
})
Run Code Online (Sandbox Code Playgroud)

但这是我在 NestJs 中的健康控制器

@Get('health')
getHealth(): string {
  return this.appService.getHealth()
}
Run Code Online (Sandbox Code Playgroud)

和 main.ts 文件。

const app = await NestFactory.create<NestFastifyApplication>(
        AppModule,
        new FastifyAdapter({
            logger: true
        }),
    )
Run Code Online (Sandbox Code Playgroud)

我不想只记录健康路线而不记录路线。

请在这方面提供帮助。

logging node.js nestjs fastify

5
推荐指数
1
解决办法
3247
查看次数

标签 统计

fastify ×1

logging ×1

nestjs ×1

node.js ×1