react-sdk icon indicating copy to clipboard operation
react-sdk copied to clipboard

[BUG] Can't set log level

Open AntonRatnick opened this issue 1 year ago • 4 comments

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

  1. Changing log level to Error, the way described in the documentation not changing console output
  2. Passing log level as part of config to createInstance also not working

React Framework

No response

Browsers impacted

No response

Link

  1. https://github.com/optimizely/react-sdk/blob/master/src/logger.tsx#L19 Here we create logger instance and pass only prefix.
  2. 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.
  3. https://github.com/optimizely/react-sdk/blob/d43cabd6f0181d504951d74822a0efd4f28aec7c/src/client.ts#L20 Here we import created logger, and use it.
  4. 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

AntonRatnick avatar Jun 19 '24 13:06 AntonRatnick

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.

alexparish avatar Jun 24 '24 15:06 alexparish

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...

Bundas avatar Jul 11 '24 16:07 Bundas

This definitely requires some attention. There are some inconsistencies that I can confirm. I have created an internal ticket FSSDK-10554 for further investigation.

junaed-optimizely avatar Aug 16 '24 13:08 junaed-optimizely

@AntonRatnick, there is a patch release v3.2.2 out with the fix. Could you please check and confirm?

junaed-optimizely avatar Aug 22 '24 12:08 junaed-optimizely

This has been fixed and in production for a while (>=v3.2.2)

junaed-optimizely avatar Nov 07 '24 11:11 junaed-optimizely