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.62k stars 7.62k forks source link

Provide an ergonomic way to set custom logger prefix #13841

Open kuncevic opened 3 months ago

kuncevic commented 3 months ago

Is there an existing issue that is already proposing this?

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

I have multiple apps using Nestjs monorepo setup. In that case if I run all apps at the same time it would be great being able easily to differentiate the log output. By default the console output starts with [Nest]... as per this line https://github.com/nestjs/nest/blob/master/packages/common/services/console-logger.service.ts#L226

In order to change this behavior you had to provide a custom logger or use another logging library. The pain here is that you must repeat that same action for each app...

Describe the solution you'd like

However I believe that it would be way easier to being able to set a custom prefix out of the box e.g app.setLoggerPrefix('my-app-name')

Teachability, documentation, adoption, migration strategy

-

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

Dev experience

WillianAgostini commented 2 months ago

Hi @kuncevic Looks a good idea! Additionally, it would be worth discussing the message format. Right now, the messages are displayed like this:

[Nest] 16680 - 15/08/2024, 23:30:49 LOG [NestApplication] Nest application successfully started +3ms
[Nest] 16680 - 15/08/2024, 23:30:49 LOG Hello world!

Do you have any ideia how to display this prefix message?

One suggestion could be:

[Nest] my-app-name 16680 - 15/08/2024, 23:30:49 LOG [NestApplication] Nest application successfully started +3ms
[Nest] my-app-name 16680 - 15/08/2024, 23:30:49 LOG Hello world!

another suggestion:

[Nest] 16680 - 15/08/2024, 23:30:49 LOG [NestApplication] [my-app-name] Nest application successfully started +3ms
[Nest] 16680 - 15/08/2024, 23:30:49 LOG [my-app-name] Hello world!

Do you have any other suggestions?

micalevisk commented 2 months ago

can't we achieve this already with https://docs.nestjs.com/techniques/logger#extend-built-in-logger ?

kuncevic commented 2 months ago

@WillianAgostini Ideally, I would see it as an exposed config option that you just stick whatever you want into, not the way it is done atm, that required a lot of boilerplate to fix. Will have to do that for each Nest project in my monorepo....painful.

kamilmysliwiec commented 2 months ago

Would you like to create a PR for this issue?