-
-
Notifications
You must be signed in to change notification settings - Fork 630
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): initOptions.debugOptionsFilter #2197
Conversation
we will review your pr... in the meantime, why not just pass your custom logger: https://www.i18next.com/misc/creating-own-plugins#logger ? |
}); | ||
|
||
describe('init log options filtering', () => { | ||
it('logs a subset of the options object', () => { |
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.
-it('logs a subset of the options object', () => {
+it('logs the options object', () => {
@@ -350,6 +350,12 @@ export interface InitOptions<T = object> extends PluginOptions<T> { | |||
*/ | |||
debug?: boolean; | |||
|
|||
/** | |||
* Filter function that allows changing the logged option value when `debug` is set to true. |
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.
but only for the log statement while init()... maybe the function name needs to respect this?
Having this |
Oh very cool! Didn't come across the logger override in my searches 🤦🏻♂️ definitely a better approach here. I'll close this... Thank you for the super quick review 🙏🏻 |
Our Issue
We're using i18next for a react-native project and we'd like to have
debug
set to true in dev mode so that we can catch issues with missing strings/keys in the logs. The problem we found is that theinitialization
log event prints a massive object to the console that, in our case, takes 3-4 full screen heights of scrolling to get through. Since this is terminal output, the object isn't interactive or collapsed like in a browser console, so there's a lot of noise in the output ([Object]
).Proposed Solution
Allow for an option (
debugOptionsFilter
) that allows for passing a function to filter the options object down to the interesting components for users. If provided, the return value would be what's logged by the logger on initialization.Other Notes
I've added two new test suites since this involves
init
and I can't re-init in the existing test suite. I've also added a separate debug suite without the filter to cover the existing behaviour when the filter function is not passed in.Some tests were failing for me locally for dates, and I assume it's a timezone issue.
If this is accepted I can update the doc site repo.
Questions
Checklist
npm run test