Skip to content

Instantly share code, notes, and snippets.

@jordangarcia
Created February 19, 2019 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordangarcia/9cee327b94ea451026bd956619f4e0dc to your computer and use it in GitHub Desktop.
Save jordangarcia/9cee327b94ea451026bd956619f4e0dc to your computer and use it in GitHub Desktop.
const core = require('@optimizely/js-sdk-core')
// this will prefix all log messages with 'myModuleName: '
const logger = createLogger('myModuleName')
logger.log(core.LogLevel.INFO, 'same .log() API as before')
// or you can use debug / info / warn / error
logger.debug('this is a debug message')
logger.info('this is an info message')
logger.warn('this is a warning')
logger.error('this is an error')
// you can also pass arguments to string interpolate
// the benefit of doing it this way is it wont be evaluated
// unless the log level should log
logger.info('user got variation "%s" for experiment "%s"', variationKey, experimentKey)
logger.error('error occurred: "%s"', ex.message)
// if the last argument passed is an error object, it will call errorHandler.handlerError
logger.warn("i got an error", ex)
// if only an error is passed it will log ex.message and call errorHandler.handlerError
logger.error(ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment