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

[BUG] Pino logger unavailable in nestjs shutdown functions #1859

Open
4 tasks done
dilshans2k opened this issue Feb 19, 2024 · 2 comments
Open
4 tasks done

[BUG] Pino logger unavailable in nestjs shutdown functions #1859

dilshans2k opened this issue Feb 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@dilshans2k
Copy link

What is the current behavior?
Using nestjs pino logger in beforeApplicationShutdown and onApplicationShutdown callbacks doesn't log in the stdout. However in onModuleDestroy using logger, logs the event. console.log works in all three callbacks.

What is the expected behavior?
Nestjs pino logger should be available in all three shutdown callbacks.

Please provide minimal example repo, not code snippet. Without example repo this issue will be closed.
https://github.com/dilshans2k/nestjs-pino-issue/tree/feature/pino-test-with-nestjspino4-pino8.18-pinohttp9
In this repo, i have app module, then a nested module inside app module and a provider 'GracefulShutdownEventLogger'. Now what i have seen is if i put a sleep in the provider 'GracefulShutdownEventLogger' in onApplicationShutdown cb (since this provider will be called the last upon application destroy), all other services application shutdown callbacks will be able to log using pino logger, but i don't know why this happens. And why do i need to wait in the 'GracefulShutdownEventLogger'.

Please mention other relevant information such as Node.js version and Operating System.
Node@16.20.2 Ubuntu 22.04

@dilshans2k dilshans2k added the bug Something isn't working label Feb 19, 2024
@dilshans2k
Copy link
Author

I learned that pino uses asynchronous logging, and their docs mention that some buffered logs might get lost on sudden system failure. I get that this can happen if the process receives a SIGKILL, but a SIGTERM or SIGINT is not a sudden failure, so pino should flush the logs properly on those signals. Maybe there is something wrong with my code. Can you please check it?

@iamolegga
Copy link
Owner

Thanks for reporting this. Unfortunately, I haven't had a chance to check this yet, I will get back to this as soon as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants