GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

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.

In the Swift SDK, you can use our default logger and configure OptimizelyLogLevel. You can initialize it with any log level and pass it in when creating an OptimizelyClient instance. You can also implement your own logger and pass it in the builder when creating an OptimizelyClient instance. See the code examples below.

class CustomLogger: OPTLogger {
    public static var logLevel: OptimizelyLogLevel = .info

    required init() {

    public func log(level: OptimizelyLogLevel, message: String) {
        if level.rawValue <= CustomLogger.logLevel.rawValue {

// create OptimizelyClient with a custom Logger
let customLogger = CustomLogger()

optimizely = OptimizelyClient(sdkKey: "<Your_SDK_Key>",
                              logger: customLogger,
@interface CustomLogger : NSObject <OPTLogger>
+ (enum OptimizelyLogLevel)logLevel;
+ (void)setLogLevel:(enum OptimizelyLogLevel)value;
- (nonnull instancetype)init;
- (void)logWithLevel:(enum OptimizelyLogLevel)level message:(NSString *)message;
@implementation CustomLogger
-(instancetype)init {
    self = [super init];
    if (self != nil) {
    return self;

- (void)logWithLevel:(enum OptimizelyLogLevel)level message:(NSString * _Nonnull)message {
    if (level <= CustomLogger.logLevel) {
        NSLog(@"%@", message);

static enum OptimizelyLogLevel logLevel = OptimizelyLogLevelInfo;
+(enum OptimizelyLogLevel)logLevel {
    return logLevel;
+(void)setLogLevel:(enum OptimizelyLogLevel)value {
    logLevel = value;

// create OptimizelyClient with a custom Logger
CustomLogger *customLogger = [[CustomLogger alloc] init];
self.optimizely = [[OptimizelyClient alloc] initWithSdkKey:@"<Your_SDK_Key>"

Log levels

The table below lists the log levels for the SDK:

Log Level



Events that prevent feature flags from functioning correctly (for example, invalid datafile in initialization and invalid flag keys) are logged. The user can take action to correct.


Events that don't prevent feature flags 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.

Events 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.


Any information related to errors that can help us debug the issue (for example, the feature flag is not running, user is not included in the flag rule) are logged.

Source files

The language/platform source files containing the implementation for Swift is OptimizelyClient.swift.

Did this page help you?