Customize the React Native SDK logger
Customize log information from the Optimizely Feature Experimentation React Native 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 Native 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:
| Constant | Description |
|---|---|
DEBUG | Logs 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 |
INFO | Logs key events to illustrate the lifecycle of an API call, such as when a decision or tracking starts and succeeds. |
WARN | Logs 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 |
ERROR | Logs 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.
Updated 20 days ago
