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

Bind pino instance to prettifier #721

Merged
merged 7 commits into from Feb 28, 2020

Conversation

SkeLLLa
Copy link
Contributor

@SkeLLLa SkeLLLa commented Oct 3, 2019

This PR passes pino instance to prettifier function.

It can be used to access configured levels, for example, here https://github.com/pinojs/pino-pretty/blob/master/lib/colors.js#L32 levels are hardcoded and if there are customLevels setup, then it will not work correctly.

Closes #720.

PS: I'm not a fan of tap, so tests might look not right.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

docs/pretty.md Outdated Show resolved Hide resolved
docs/pretty.md Outdated Show resolved Hide resolved
docs/pretty.md Outdated Show resolved Hide resolved
docs/pretty.md Outdated Show resolved Hide resolved
lib/tools.js Outdated Show resolved Hide resolved
lib/tools.js Outdated Show resolved Hide resolved
pino.js Outdated Show resolved Hide resolved
@@ -96,7 +97,7 @@ function pino (...args) {
assertDefaultLevelFound(level, customLevels, useOnlyCustomLevels)
const levels = mappings(customLevels, useOnlyCustomLevels)

const instance = {
Object.assign(instance, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid doing this? It will slow down init time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called only once and the difference between Object.assign and {} will be nanoseconds. So Comparing to other code and node itself there will be less than statistical uncertainty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just run once.. this might be relevant only for serverless if at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this has a side effect, as all the definitions of the hidden class would not be done in the same place.
Can you revert?

(Good spot @davidmarkclements).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If instance is needed to be passed to normalize function then it should be defined before calling normalize. And normalize returns opts that are used for constructing the instance. So I don't know what's the way of avoiding this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might not be needed at all.

In

lastLogger: null,
you have the last logger object used. You might just call
const formatted = pretty(typeof redact === 'function' ? redact(obj) : obj)
with pretty.call(this.lastLogger, ...) instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkeLLLa how about resolving this so we can merge?

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@davidmarkclements
Copy link
Member

davidmarkclements commented Oct 4, 2019 via email

@mcollina
Copy link
Member

mcollina commented Oct 4, 2019

That’s assuming that everyone uses child loggers instead of new instances.
I’ve seen the latter in the wild

I've seen that happen only at module scope/maybe 10 or 20 times within a project. In other terms, this does not sit in a hot path for me.

@davidmarkclements
Copy link
Member

davidmarkclements commented Oct 4, 2019 via email

@davidmarkclements
Copy link
Member

davidmarkclements commented Oct 4, 2019 via email

@jsumners
Copy link
Member

@davidmarkclements have your concerns been addressed?

@davidmarkclements
Copy link
Member

@jsumners yeah lgtm

@github-actions
Copy link

github-actions bot commented Feb 3, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to pino instance from prettifier function
4 participants