Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ public class FlutterLogbackAppender extends AppenderBase<ILoggingEvent> {
public static MethodChannel channel;
private static final Handler mainThreadHandler = new Handler(Looper.getMainLooper());

public static void setChannel(MethodChannel channel) {
FlutterLogbackAppender.channel = channel;
public static void setChannel(MethodChannel newChannel) {
if (channel == null) {
channel = newChannel;
}
}

public static void clearChannel() {
channel = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
if (channel != null) {
return;
}
channel = new MethodChannel(binding.getBinaryMessenger(), "optimizely_flutter_sdk");
channel.setMethodCallHandler(this);
context = binding.getApplicationContext();
Expand All @@ -232,15 +235,16 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
channel = null;
// Stop and detach the appender
if (flutterLogbackAppender != null) {
Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAppender(flutterLogbackAppender);
flutterLogbackAppender.stop();
flutterLogbackAppender = null;
}
// Clean up the channel
FlutterLogbackAppender.setChannel(null);
// Clean up the logger channel
FlutterLogbackAppender.clearChannel();
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion ios/Classes/OptimizelyFlutterLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public class OptimizelyFlutterLogger: NSObject, OPTLogger {
}

public static func setChannel(_ channel: FlutterMethodChannel) {
loggerChannel = channel
if loggerChannel == nil {
loggerChannel = channel
}
}

public static func clearChannel() {
loggerChannel = nil
}

public func log(level: OptimizelyLogLevel, message: String) {
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/SwiftOptimizelyFlutterSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class SwiftOptimizelyFlutterSdkPlugin: NSObject, FlutterPlugin {

/// Registers optimizely_flutter_sdk channel to communicate with the flutter sdk to receive requests and send responses
public static func register(with registrar: FlutterPluginRegistrar) {
if channel != nil {
return
}
channel = FlutterMethodChannel(name: "optimizely_flutter_sdk", binaryMessenger: registrar.messenger())
let instance = SwiftOptimizelyFlutterSdkPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
Expand Down
Loading