nest icon indicating copy to clipboard operation
nest copied to clipboard

Provide an ergonomic way to set custom logger prefix

Open kuncevic opened this issue 1 year ago • 4 comments
trafficstars

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

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

kuncevic avatar Jul 30 '24 06:07 kuncevic

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?

WillianAgostini avatar Aug 16 '24 02:08 WillianAgostini

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

micalevisk avatar Aug 16 '24 02:08 micalevisk

@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.

kuncevic avatar Aug 21 '24 13:08 kuncevic

Would you like to create a PR for this issue?

kamilmysliwiec avatar Aug 22 '24 06:08 kamilmysliwiec

https://github.com/nestjs/nest/pull/14121

kamilmysliwiec avatar Nov 08 '24 14:11 kamilmysliwiec