[BUG] Can't set log level
Is there an existing issue for this?
- [X] I have searched the existing issues
SDK Version
3.1.1
Current Behavior
Setting log level to Error, don't reduce amount of warnings and info logs in console
Expected Behavior
If log level == Error no info or warning logs appear in console.
Steps To Reproduce
- Changing log level to Error, the way described in the documentation not changing console output
- Passing log level as part of config to
createInstancealso not working
React Framework
No response
Browsers impacted
No response
Link
- https://github.com/optimizely/react-sdk/blob/master/src/logger.tsx#L19 Here we create logger instance and pass only prefix.
- https://github.com/optimizely/javascript-sdk/blob/4909efb74335b754592ddf6e8415047fc0bf3e7b/lib/modules/logging/logger.ts#L99 If I am not mistaken this is the logger we creating, without any arguments beside the prefix.
- https://github.com/optimizely/react-sdk/blob/d43cabd6f0181d504951d74822a0efd4f28aec7c/src/client.ts#L20 Here we import created logger, and use it.
- The logger instance created for React SDK is not exported, so changing log level on created instance also not possible.
Logs
No response
Severity
No response
Workaround/Solution
No response
Recent Change
No response
Conflicts
No response
I was just in the process of creating a bug for this exact scenario. Luckily saw this one first!
It's frustrating that, as a consumer, I cannot change the log level of the react-sdk internal logger as it is causing a lot of unnecessary log noise for my services in certain scenarios.
I was poking around and it seems like the easiest solution is to export the instance of logger in src/logger.tsx called logHandler. Once it is exported, we can access it at a constructor of OptimizelyReactSDKClient in src/client.ts and set a proper log level based on the config there. I tested it locally and it works like a charm. Unfortunately I can't create a PR at this time, so if anybody has a capacity...
This definitely requires some attention. There are some inconsistencies that I can confirm. I have created an internal ticket FSSDK-10554 for further investigation.
@AntonRatnick, there is a patch release v3.2.2 out with the fix. Could you please check and confirm?
This has been fixed and in production for a while (>=v3.2.2)