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

How should a Pino instance be identified in runtime? #1984

Open
gerardo-lima-moonfare opened this issue Jun 3, 2024 · 1 comment
Open

How should a Pino instance be identified in runtime? #1984

gerardo-lima-moonfare opened this issue Jun 3, 2024 · 1 comment

Comments

@gerardo-lima-moonfare
Copy link

First of all, thank you very much for the great work!

I am trying to assess a runtime object is an instance of Pino. I found that pino instances do have a constructor, though it's not exported to consumers:

const constructor = class Pino {}

I can, then, use logger.constructor.name === 'Pino', but I wonder whether it would make sense to export this class, to allow logger instanceOf Pino.

@jsumners
Copy link
Member

jsumners commented Jun 3, 2024

Don't trust the instanceof operator fastify/fastify-error#86 (comment)

Generally, to accomplish what you're asking about you should test if the methods you expect are present on the object.

Personally, I would not be opposed to exposing a read-only property that indicates the object is a Pino instance.

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