-
Notifications
You must be signed in to change notification settings - Fork 4
[FSSDK-11853] add swift logger support #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
be95ef5
build: add Optimizely SDK logger classes
muzahidul-opti 9b4c6fe
fix: resolve logging inconsistencies
muzahidul-opti 2f88840
refactor: update logger imports
muzahidul-opti 6336b0c
feat: add custom logger implementation
muzahidul-opti 40cfdaa
refactor: rename logger classes in Android and iOS
muzahidul-opti 8b401ca
feat: update logging behavior for Optimizely SDK
muzahidul-opti bde2659
feat: add methods and tests for logger state management
muzahidul-opti 6993bfc
feat: add separate logger channel for outgoing log calls
muzahidul-opti 9b26c39
refactor: improve main thread dispatch for Flutter method channel calls
muzahidul-opti a0a9ca9
chore: clean up logger implementation
muzahidul-opti 8edc431
style: update comment in sendLogToFlutter method
muzahidul-opti 49ed2dc
chore: remove unused import statement
muzahidul-opti 7ae86de
chore: update log messages and method channel handling
muzahidul-opti e6404aa
refactor: enhance logging functionalities
muzahidul-opti c2f1507
test: add global logging functions test cases
muzahidul-opti 4b54235
Merge branch 'master' into muzahid/custom-looger
muzahidul-opti 387adc5
chore: remove custom logger functionality
muzahidul-opti 675e3cd
refactor: rename customLogger to useCustomLogger
muzahidul-opti 92256ae
clean up
muzahidul-opti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import 'package:optimizely_flutter_sdk/optimizely_flutter_sdk.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| class CustomLogger implements OptimizelyLogger { | ||
| @override | ||
| void log(OptimizelyLogLevel level, String message) { | ||
| if (kDebugMode) { | ||
| print('[OPTIMIZELY] ${level.name.toUpperCase()}: $message'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import Flutter | ||
| import Optimizely | ||
|
|
||
| public class OptimizelyFlutterLogger: NSObject, OPTLogger { | ||
| static var LOGGER_CHANNEL: String = "optimizely_flutter_sdk_logger"; | ||
|
|
||
| public static var logLevel: OptimizelyLogLevel = .info | ||
|
|
||
| private static var loggerChannel: FlutterMethodChannel? | ||
|
|
||
| public required override init() { | ||
| super.init() | ||
| } | ||
|
|
||
| public static func setChannel(_ channel: FlutterMethodChannel) { | ||
| loggerChannel = channel | ||
| } | ||
|
|
||
| public func log(level: OptimizelyLogLevel, message: String) { | ||
| // Early return if level check fails | ||
| guard level.rawValue <= OptimizelyFlutterLogger.logLevel.rawValue else { | ||
| return | ||
| } | ||
|
|
||
| // Ensure we have a valid channel | ||
| guard let channel = Self.loggerChannel else { | ||
| print("[OptimizelyFlutterLogger] ERROR: No logger channel available!") | ||
| return | ||
| } | ||
|
|
||
| // https://docs.flutter.dev/platform-integration/platform-channels#jumping-to-the-main-thread-in-ios | ||
| DispatchQueue.main.async { | ||
| channel.invokeMethod("log", arguments: [ | ||
| "level": level.rawValue, | ||
| "message": message | ||
| ]) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import 'package:optimizely_flutter_sdk/src/data_objects/log_level.dart'; | ||
|
|
||
| abstract class OptimizelyLogger { | ||
| /// Log a message at a certain level | ||
| void log(OptimizelyLogLevel level, String message); | ||
| } | ||
|
|
||
| class DefaultOptimizelyLogger implements OptimizelyLogger { | ||
| @override | ||
| void log(OptimizelyLogLevel level, String message) { | ||
| print('[OPTIMIZELY] [${level.name.toUpperCase()}]: $message'); | ||
| } | ||
| } | ||
|
|
||
| /// App logger instance | ||
| final _appLogger = DefaultOptimizelyLogger(); | ||
|
|
||
| /// App logging functions | ||
| void logError(String message) => | ||
| _appLogger.log(OptimizelyLogLevel.error, message); | ||
| void logWarning(String message) => | ||
| _appLogger.log(OptimizelyLogLevel.warning, message); | ||
| void logInfo(String message) => | ||
| _appLogger.log(OptimizelyLogLevel.info, message); | ||
| void logDebug(String message) => | ||
| _appLogger.log(OptimizelyLogLevel.debug, message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import 'dart:async'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:optimizely_flutter_sdk/src/logger/flutter_logger.dart'; | ||
| import 'package:optimizely_flutter_sdk/optimizely_flutter_sdk.dart'; | ||
|
|
||
| class LoggerBridge { | ||
| static const MethodChannel _loggerChannel = | ||
| MethodChannel('optimizely_flutter_sdk_logger'); | ||
| static OptimizelyLogger? _customLogger; | ||
|
|
||
| /// Initialize the logger bridge to receive calls from native | ||
| static void initialize(OptimizelyLogger? logger) { | ||
| logInfo('[LoggerBridge] Initializing with logger: ${logger != null}'); | ||
| _customLogger = logger; | ||
| _loggerChannel.setMethodCallHandler(_handleMethodCall); | ||
| } | ||
|
|
||
| /// Handle incoming method calls from native Swift/Java code | ||
| static Future<void> _handleMethodCall(MethodCall call) async { | ||
| try { | ||
| switch (call.method) { | ||
| case 'log': | ||
| await _handleLogCall(call); | ||
| break; | ||
| default: | ||
| logWarning('[LoggerBridge] Unknown method call: ${call.method}'); | ||
| } | ||
| } catch (e) { | ||
| logError('[LoggerBridge] Error handling method call: $e'); | ||
| } | ||
| } | ||
|
|
||
| /// Process the log call from Swift/Java | ||
| static Future<void> _handleLogCall(MethodCall call) async { | ||
| try { | ||
| final args = Map<String, dynamic>.from(call.arguments ?? {}); | ||
|
|
||
| final levelRawValue = args['level'] as int?; | ||
| final message = args['message'] as String?; | ||
|
|
||
| if (levelRawValue == null || message == null) { | ||
| logError('[LoggerBridge] Warning: Missing level or message in log call'); | ||
| return; | ||
| } | ||
|
|
||
| final level = _convertLogLevel(levelRawValue); | ||
|
|
||
| if (_customLogger != null) { | ||
| _customLogger!.log(level, message); | ||
| } else { | ||
| logInfo('[Optimizely ${level.name}] $message'); | ||
| } | ||
| } catch (e) { | ||
| logError('[LoggerBridge] Error processing log call: $e'); | ||
| } | ||
| } | ||
|
|
||
| /// Convert native log level to Flutter enum | ||
| static OptimizelyLogLevel _convertLogLevel(int rawValue) { | ||
| switch (rawValue) { | ||
| case 1: | ||
| return OptimizelyLogLevel.error; | ||
| case 2: | ||
| return OptimizelyLogLevel.warning; | ||
| case 3: | ||
| return OptimizelyLogLevel.info; | ||
| case 4: | ||
| return OptimizelyLogLevel.debug; | ||
| default: | ||
| return OptimizelyLogLevel.info; | ||
| } | ||
| } | ||
|
|
||
| /// Expose convertLogLevel | ||
| static OptimizelyLogLevel convertLogLevel(int rawValue) { | ||
| return _convertLogLevel(rawValue); | ||
| } | ||
|
|
||
| /// Check if a custom logger is set | ||
| static bool hasLogger() { | ||
| return _customLogger != null; | ||
| } | ||
|
|
||
| /// Get the current logger | ||
| static OptimizelyLogger? getCurrentLogger() { | ||
| return _customLogger; | ||
| } | ||
|
|
||
| /// Reset logger state | ||
| static void reset() { | ||
| _customLogger = null; | ||
| } | ||
|
|
||
| /// Simulate method calls | ||
| static Future<void> handleMethodCallForTesting(MethodCall call) async { | ||
| await _handleMethodCall(call); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.