Customize logger

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

To improve your experience setting up the SDK and configuring your production environment, we recommend that you pass in a logger for your Optimizely client. See the code examples below.

CustomLogger *customLogger = [[CustomLogger alloc] init];

OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.logger = customLogger;
}]];

OPTLYLoggerDefault *optlyLogger = [[OPTLYLoggerDefault alloc] initWithLogLevel:OptimizelyLogLevelAll];
OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.logger = optlyLogger;
}]];
let customLogger: CustomLogger? = CustomLogger()

let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder?.sdkKey = "SDK_KEY_HERE"
  builder?.logger = customLogger
}))

let optlyLogger: OPTLYLoggerDefault? = OPTLYLoggerDefault(logLevel: OptimizelyLogLevel.all)

let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder?.sdkKey = "SDK_KEY_HERE"
  builder?.logger = optlyLogger
}))

Log levels

The log levels vary slightly among SDKs but are generally as follows:

Log Level

Explanation

CRITICAL

Events that cause the app to crash are logged.

ERROR

Events that prevent experiments from functioning correctly (for example, invalid datafile in initialization and invalid experiment keys or event keys) are logged. The user can take action to correct.

WARNING

Events that don't prevent experiments from functioning correctly, but can have unexpected outcomes (for example, future API deprecation, logger or error handler are not set properly, and nil values from getters) are logged.

INFO

Events of significance (for example, activate started, activate succeeded, tracking started, and tracking succeeded) are logged. This is helpful in showing the lifecycle of an API call.

DEBUG

Any information related to errors that can help us debug the issue (for example, experiment is not running, user is not in experiment, and the bucket value generated by our helper method) are logged.

Default logging

You can use our default logger and configure OptimizelyLogLevelInfo. You can initialize it with any log level and pass it in when creating an Optimizely instance. You can also implement your own logger and pass it in the builder when creating an Optimizely instance.


Did this page help you?