-
Notifications
You must be signed in to change notification settings - Fork 139
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
feat(logger): add silent log level to suppress the emission of all logs #1347
feat(logger): add silent log level to suppress the emission of all logs #1347
Conversation
It's also worth mentioning in a |
I agree that we should update the docs but I'm still unsure about where it should go. At the moment I'm leaning towards this not being a test-only use case, especially if we keep in mind the use case that influenced the feature being green lit. If that's okay for you, let's start with the implementation and unit tests, and maybe also adding the new value to this table. This will give me some more time to think about how to frame this new feature. |
@@ -169,7 +203,7 @@ describe('Class: Logger', () => { | |||
|
|||
// Prepare | |||
const logger: Logger = createLogger({ | |||
logLevel: 'ERROR', | |||
logLevel: 'SILENT', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to the highest log level when it doesn't print to stdout from any method and still prints when the sample rate is 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate on this one? Not sure I'm following
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case consists of two tests: testing with and w/o sample rate.
For the first one, it is needed to show that no logs emit with the higher log level. The error
log level was used to show that it doesn't print to stdout from all methods and is ignored on the error
method:
expect(consoleSpy).toBeCalledTimes(method === 'error' ? 1 : 0)
Now we have silence
as the highest level, so I changed to it.
The second one test that all logs emit with sample rate for every method even with the highest log level.
I pointed out this, because this is a dynamic set of tests, and it wasn't obvious to me what is "higher" level means in the description, and why it uses a particular log level. So I thought it worth mentioning in the review.
Take your time and then let me know! |
Regarding the docs, I think we should add a new section under "Advanced", and right after "Sampling logs", titled "Silencing logs":
Then also add a "Note" box/callout that says:
(Housekeeping) Also, since you're editing that file already, could you please fix these two:
|
You found a good place for this feature in the docs. Good job, Andrea! I paraphrased the text a bit. I hope it's suitable and you like it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, thanks for the help on this one.
Let's 🚢 it!
Description of your changes
This PR introduces a new
logLevel
valueSILENT
. When this level is set, either via constructor or via environment variable, the utility does not emit any log regardless of where it's running.Constructor example:
Environment variable example:
This behavior is desirable for those customers who would like to have the ability to instrument their code with logs, but optionally have the chance to suppress them based on their requirements (see #1198 (comment) for example).
Resolves #1198.
How to verify this change
N/A
Related issues, RFCs
Issue number: #1198
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.