Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Customize the JavaScript SDK logger v6+

How to customize the log information about experiments coming from the Optimizely Feature Experimentation JavaScript SDK versions 6 and above to help with debugging.

❗️

Warning

This content covers the Feature Experimentation JavaScript SDK v6 features currently in pre-production testing and is subject to change before release.

The logger records information about your experiments to help you with debugging. You can customize where log information is sent and what kind of information is tracked.

Minimum SDK version

v6.0.0+

For versions 5.3.5 and below, see JavaScript (Browser) SDK or JavaScript (Node) SDK. See the SDK compatibility matrix documentation for a list of current SDK releases and the features they support.

Description

To enable logging for the Javascript SDK, create a logger using the createLoggerfactory function and pass the logger to createInstance.

import {
  createInstance,
  createPollingProjectConfigManager,
  createLogger,
  INFO
} from "@optimizely/optimizely-sdk";

const SDK_KEY = "YOUR_SDK_KEY";

const pollingConfigManager = createPollingProjectConfigManager({
  sdkKey: SDK_KEY,
});

const logger = createLogger({
  level: INFO,
});

const optimizely = createInstance({
  projectConfigManager: pollingConfigManager,
  logger
});

To customize the logger instance, you could use following configuration:

ParameterTypeDescription
levelOpaqueLevelPresetLevel presets that can be used directly to create logger instance.
logHandler
optional
LogHandlerAn interface that implements the log method. A custom LogHandlercan be used to modify how log messages are handled (for example, storing in a file or sending to an external system). By default, a console log handler is used which prints the log message to the console.

Log level presets

The following table lists the log level presets for the JavaScript SDK:

Log LevelExplanation
ERROREvents that prevent feature flags or experiments from functioning correctly (for example, invalid datafile in initialization and invalid feature keys) are logged. You can take action to correct.
WARNEvents that do not prevent feature flags or experiments from functioning correctly, but can have unexpected outcomes (for example, future API deprecation, logger or error handler are not set properly) are logged.
INFOEvents of significance (for example, decision started, decision succeeded, tracking started, and tracking succeeded) are logged. This is helpful in showing the lifecycle of an API call.
DEBUGAny information related to errors that can help you debug the issue (for example, the feature flag is not running, user is not included in the rollout) are logged.