Visitar URL original
Implement js-sdk-logging in optimizely-sdk by jordangarcia · Pull Request #232 · optimizely/javascript-sdk · GitHub
The Wayback Machine - https://web.archive.org/web/20200920090839/https://github.com/optimizely/javascript-sdk/pull/232
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

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

Merged
merged 35 commits into from Mar 1, 2019

Conversation

@jordangarcia
Copy link
Contributor

jordangarcia commented Feb 22, 2019

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.
@jordangarcia jordangarcia requested review from mjc1283 and mikeng13 Feb 22, 2019
Copy link
Contributor

mjc1283 left a comment

LGTM, just a few small questions.

}
config = config || {};

// TODO warn about setting per instance errorHandler / logger / logLevel

This comment has been minimized.

@mjc1283

mjc1283 Feb 28, 2019 Contributor

Should we just do this now?

This comment has been minimized.

@jordangarcia

jordangarcia Mar 1, 2019 Author Contributor

Yeah I can do that.


/**
* Default logger implementation
*/
function NoOpLogger() {}

This comment has been minimized.

@mjc1283

mjc1283 Feb 28, 2019 Contributor

Is NoOpLogger needed anymore?

This comment has been minimized.

@jordangarcia

jordangarcia Mar 1, 2019 Author Contributor

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,

This comment has been minimized.

@mjc1283

mjc1283 Feb 28, 2019 Contributor

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?

This comment has been minimized.

@jordangarcia

jordangarcia Mar 1, 2019 Author Contributor

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 Mar 1, 2019
@jordangarcia jordangarcia requested a review from mjc1283 Mar 1, 2019
@mjc1283
mjc1283 approved these changes Mar 1, 2019
Copy link
Contributor

mjc1283 left a comment

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);

This comment has been minimized.

@mjc1283

mjc1283 Mar 1, 2019 Contributor

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?

This comment has been minimized.

@jordangarcia

jordangarcia Mar 1, 2019 Author Contributor

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.

This comment has been minimized.

@mjc1283

mjc1283 Mar 1, 2019 Contributor

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
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
optimizely/fullstack-sdk-compatibility-suite (javascript) Build result: success
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.