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

Added isLevelEnabled(string) & isXXXEnabled() #1352

Merged
merged 1 commit into from
Aug 27, 2018

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented Jun 5, 2018

Make logger expose functions to check if a particular level is enabled. This could be useful if either message or parameter creation is an expensive operation, which should be avoided when log level is disabled.

Logger will contain isLevelEnabled(level: string) function and multiple isXXXEnabled() where "XXX" is the capitalized name of the configured log level. E.g. isDebugEnabled(), isInfoEnabled(), etc.

Resolves #905

@lutovich
Copy link
Contributor Author

lutovich commented Jun 5, 2018

Hello and thanks for this logging library!

This PR is a proposal and requires some cleanup - tests could be improved and jsdocs are missing. Please let me know if this is even a valid approach and useful feature in general.

@indexzero
Copy link
Member

Thanks for submitting this PR. This was a previously requested feature, I don't see any strong reason why this won't land soon.

@lutovich
Copy link
Contributor Author

@indexzero do you think implementation in this PR is acceptable? does it require any adjustments?

@indexzero
Copy link
Member

@lutovich looks like I made some changes in another PR that caused git conflicts here. Would you mind resolving them? Then we should be good to go for merging this 😸

Make logger expose functions to check if a particular level is enabled.
This could be useful if either message or parameter creation is an
expensive operation, which should be avoided when log level is disabled.

Logger will contain `isLevelEnabled(level: string)` function and
multiple `isXXXEnabled()` where "XXX" is the capitalized name of the
configured log level. E.g. `isDebugEnabled()`, `isInfoEnabled()`, etc.
@lutovich
Copy link
Contributor Author

@indexzero PR is now rebased :)

@mjgp2
Copy link

mjgp2 commented Jul 26, 2018

Would be awesome to merge and release this :)

@kingnebby
Copy link

In Winston 1.X I remember the logger would do this kind of check up front and therefore not process the second arg (the meta or whatever it's called). We noticed performance decrease in certain cases after we moved to Winston 2.X because this was no longer the case.

Any change this request can go one step future and embed the logic in the logger.log() method? We actually wrapped our Winston logger in a Proxy to do exactly this.

@DABH DABH merged commit 908c300 into winstonjs:master Aug 27, 2018
@lutovich lutovich deleted the is-level-enabled branch August 27, 2018 17:41
@DABH
Copy link
Contributor

DABH commented Aug 27, 2018

Just merged this – it will go out in the next release, which should hopefully be published very soon.

I think the comment above is describing a separate issue about the behavior of the log function. If you see any places where we are not correctly optimizing for the hot paths, especially in the log function, on master, please feel free to open a separate issue or PR so we can take a look. Thanks!

@kingnebby
Copy link

@DABH thank you for all you do! And yes, in the off chance I get some spare time I'll try to put together something formal. 🎩

Mizumaki pushed a commit to Mizumaki/winston that referenced this pull request Jun 11, 2020
Make logger expose functions to check if a particular level is enabled.
This could be useful if either message or parameter creation is an
expensive operation, which should be avoided when log level is disabled.

Logger will contain `isLevelEnabled(level: string)` function and
multiple `isXXXEnabled()` where "XXX" is the capitalized name of the
configured log level. E.g. `isDebugEnabled()`, `isInfoEnabled()`, etc.
@peternann
Copy link

peternann commented Aug 16, 2022

Did this ever get documented anywhere though?

I can only find mention of it in GitHub threads. This is a very important feature for efficient log practices at high scale and should be in the docs I would say!

@DABH
Copy link
Contributor

DABH commented Aug 16, 2022

@peternann If you don’t spot anything relevant in the docs, I’m sure other devs have similar feelings :) A PR is welcomed!

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

Successfully merging this pull request may close these issues.

isLevelEnabled / isDebugEnabled check possible?
6 participants