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 React SDK logger

Customize log information from the Optimizely Feature Experimentation React SDK for debugging experiments.

The logger captures details about your experiments, making it easier for you to debug them. You can customize where the log information is stored and choose the types of data you want to track.

Minimum SDK version

v4.0.0+

For versions 3.x and earlier, see React SDK prior to v4.

In v4, logging is disabled by default. You must pass a logger to createInstance to enable it. The setLogLevel and setLogger functions from v3 are removed.

Enable logging

Use the createLogger factory function to create a logger instance and pass it to createInstance:

import {
  createInstance,
  createPollingProjectConfigManager,
  createLogger,
  DEBUG,
} from '@optimizely/react-sdk';

const optimizely = createInstance({
  projectConfigManager: createPollingProjectConfigManager({
    sdkKey: 'YOUR_SDK_KEY',
  }),
  logger: createLogger({ logLevel: DEBUG }),
});

Log level constants

The following log level constants are exported from the SDK for convenience:

ConstantDescription
DEBUGLogs extra information related to errors that aid Optimizely in debugging, like when a feature flag is not running or a user is not included in a rollout
INFOLogs key events to illustrate the lifecycle of an API call, such as when a decision or tracking starts and succeeds.
WARNLogs events that do not prevent feature flags from working properly but may cause unexpected results, such as future API deprecation, improper logger or error handler settings, and null values from getters
ERRORLogs events that prevent feature flags from working properly, such as an invalid data file during initialization or incorrect feature keys. These issues require user intervention to fix.
import {
  createLogger,
  DEBUG,
  INFO,
  WARN,
  ERROR,
} from '@optimizely/react-sdk';

// Create a logger with INFO level
const logger = createLogger({ logLevel: INFO });

Disable logging

To disable logging (the default behavior in v4), simply omit the logger parameter when calling createInstance.