nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.89k stars 7.66k forks source link

[Feature Request] @nestjs/platform-fastify support Custom Log Level #14137

Open daimalou opened 1 week ago

daimalou commented 1 week ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

I use fastify buildin logger, this logger is awesome, has builtin traceId feature and can access by request.log.info()

https://fastify.dev/docs/v4.28.x/Reference/Logging/

It works.

  const fastifyInstance = fastify({
    logger: true,
  });

  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(fastifyInstance),
    {
      logger: false,
    },
  );

But this logger log every request and response. I find a solution to close some route. But In Nest I can't find place to config.

solution: https://github.com/fastify/fastify/issues/2120 https://github.com/fastify/help/issues/140 https://fastify.dev/docs/latest/Reference/Routes/#custom-log-level

Describe the solution you'd like

Give a config.

Teachability, documentation, adoption, migration strategy

None

What is the motivation / use case for changing the behavior?

None

Tony133 commented 4 days ago

If I understand you correctly, you want to know how to use request.log.info(), with @nestjs/platform-fastify package ?

daimalou commented 3 days ago

@Tony133, I need a configuration in nest to close some route log.

like this fastify.register(require('./routes/your-route'), { logLevel: 'silent' })

daimalou commented 3 days ago

I found the key code. I'll try modifying it. https://github.com/nestjs/nest/tree/master/packages/platform-fastify/decorators https://github.com/nestjs/nest/blob/master/packages/platform-fastify/adapters/fastify-adapter.ts#L726