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

Passing an existing instance #27

Open
net-tech opened this issue Jan 15, 2025 · 4 comments
Open

Passing an existing instance #27

net-tech opened this issue Jan 15, 2025 · 4 comments
Assignees

Comments

@net-tech
Copy link

Hi there,

I already use Pino for my app and was considering adding Elysia. Is there a way to pass my current Pino instance into Elysia?

Thanks.

@bogeychan
Copy link
Owner

bogeychan commented Jan 16, 2025

Hi, passing an existing instance is not supported atm, you can use the createPinoLogger function from this plugin to create a standalone (pino) logger for use outside the Elysia handler context instead, as stated in the README. It supports all pino options:

const log = createPinoLogger({

To integrate it into an Elysia instance, call app.use(log.into()) as you would with any plugin.

.use(log.into()) // Call `into` to use the logger instance in both `ctx` and standalone

log.into(...) allows additional options to customize its behavior in Elysia.


Does this work for your scenario?

@bogeychan
Copy link
Owner

bogeychan commented Jan 16, 2025

If you use custom formatters or serializers in your logger logic, ensure you include those provided by this plugin to maintain its usual behavior:

formatters: {
...formatters,

They are only set if the createPinoLogger options are undefined-like:

options.formatters ??= formatters;
options.serializers ??= serializers;

@bogeychan bogeychan self-assigned this Jan 16, 2025
@net-tech
Copy link
Author

While that works, its not ideal since it is still creating another Pino instance and any changes we make in one setup need to be copied over to the other. Is there any chance this issue could become a feature request?

@bogeychan
Copy link
Owner

The idea is to replace the old pino instance with createPinoLogger instead of 2. Does that cause any issues for you?

If so, can you please share more information/code snippet on how you create / manage your pino instance?


I'll look into adding this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants