Skip to content

Implement js-sdk-logging in optimizely-sdk #232

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

Merged
merged 35 commits into from
Mar 1, 2019

Conversation

jordangarcia
Copy link
Contributor

Summary

  • Inject the new LoggerFacade and use as the logger
  • Change createLogger() and createNoopLogger()
  • Update tests to work with new logger

Test plan

  • Existing unit tests
  • I've compared log outputs from a stock 3.0.1 optimizely-sdk and this one to verify they work the same.

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few small questions.

}
config = config || {};

// TODO warn about setting per instance errorHandler / logger / logLevel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just do this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can do that.


/**
* Default logger implementation
*/
function NoOpLogger() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is NoOpLogger needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it around. The preferred way of setting no-op logging is to just call optimizelySDK.setLogger(null).

But people are using NoOpLogger today, so we need to keep it in.

{
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
// always get the OptimizelyLogger facade from logging
logger: logger,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still passing a logger into Optimizely. I thought the plan was to stop passing logger around and instead import the singleton wherever necessary. Is that still true/would we implement this in follow-up PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the internal logger passing in place since it reduces the risk of this breaking anything.

As we rewrite things we should be using the singleton. I didn't see any benefit in doing that now, best case scenario things work exactly as before, worse case scenario the SDK breaks.

@jordangarcia jordangarcia force-pushed the jordan/implement-core-logger branch from d54d901 to bedf9a2 Compare March 1, 2019 18:36
@jordangarcia jordangarcia requested a review from mjc1283 March 1, 2019 20:25
Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one final question.

} else {
var simpleLogger = logger.createLogger({logLevel: 4});
simpleLogger.log(enums.LOG_LEVEL.ERROR, sprintf('%s: %s', MODULE_NAME, ex.message));
console.error(ex.message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this earlier. But should we be referring to console outside of the console log handler? I get that we want to emit something even when no logger is specified, but maybe we can just add a console log handler temporarily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite see the point in creating a ConsoleLogHandler just to call it once. I feel like we shouldn't be using the LogHandlers now and only interacting with the Facade.

The result of this whole thing was just to console.error something. So why not just console.error something directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let's merge it.

@coveralls
Copy link

coveralls commented Mar 1, 2019

Coverage Status

Coverage increased (+0.06%) to 97.649% when pulling fd305e9 on jordan/implement-core-logger into 659628e on master.

@jordangarcia jordangarcia merged commit 1d9e6b7 into master Mar 1, 2019
@raju-opti raju-opti deleted the jordan/implement-core-logger branch October 4, 2023 13:34
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.

3 participants