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

feat(logger): initOptions.debugOptionsFilter #2197

Closed
wants to merge 1 commit into from

Conversation

sterlingwes
Copy link

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 the initialization 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

  • should i run the build command? (i notice there's a UMD file in the root of the repo)

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • commit message and code follows the Developer's Certification of Origin

@coveralls
Copy link

Coverage Status

coverage: 96.479% (+0.1%) from 96.341%
when pulling ad43db7 on sterlingwes:feat/init-log-filter
into c8d9f7b on i18next:master.

@adrai adrai requested a review from jamuhl May 22, 2024 04:35
@adrai
Copy link
Member

adrai commented May 22, 2024

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', () => {
Copy link
Member

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.
Copy link
Member

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?

@adrai
Copy link
Member

adrai commented May 22, 2024

Having this debugOptionsFilter option is very restrictive only for the log statement done in the init()...
Passing a custom logger module is more flexibel...

@sterlingwes
Copy link
Author

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 🙏🏻

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.

None yet

3 participants