Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an ergonomic way to set custom logger prefix #13841

Closed
1 task done
kuncevic opened this issue Jul 30, 2024 · 5 comments
Closed
1 task done

Provide an ergonomic way to set custom logger prefix #13841

kuncevic opened this issue Jul 30, 2024 · 5 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@kuncevic
Copy link

kuncevic commented Jul 30, 2024

Is there an existing issue that is already proposing this?

  • 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 kuncevic added needs triage This issue has not been looked into type: enhancement 🐺 labels Jul 30, 2024
@WillianAgostini
Copy link

WillianAgostini commented Aug 16, 2024

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
Copy link
Member

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

@kuncevic
Copy link
Author

@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
Copy link
Member

Would you like to create a PR for this issue?

@kamilmysliwiec
Copy link
Member

#14121

@nestjs nestjs locked and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

4 participants