Skip to content

Commit 461abba

Browse files
authored
feat: add support for logging (#31)
1 parent 958fe29 commit 461abba

18 files changed

+65
-24
lines changed

.github/workflows/android-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
env:
1414
FLUTTER_CHANNEL: stable
15-
FLUTTER_VERSION: 3.22.2
15+
FLUTTER_VERSION: 3.27.3
1616

1717
steps:
1818
- name: Checkout code

.github/workflows/ci.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
env:
1414
FLUTTER_CHANNEL: stable
15-
FLUTTER_VERSION: 3.22.2
15+
FLUTTER_VERSION: 3.27.3
1616

1717
steps:
1818
- name: Checkout code
@@ -21,11 +21,12 @@ jobs:
2121
- name: fetch submodules
2222
run: git submodule update --init --recursive
2323

24-
- name: Set up JDK 11
24+
- name: Set up JDK 17
2525
uses: actions/setup-java@v3
2626
with:
27-
java-version: 11
27+
java-version: 17
2828
distribution: 'zulu'
29+
2930
- name: Set up Flutter
3031
uses: subosito/flutter-action@v2
3132
with:

.github/workflows/ios-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
env:
1414
FLUTTER_CHANNEL: stable
15-
FLUTTER_VERSION: 3.22.2
15+
FLUTTER_VERSION: 3.27.3
1616

1717
steps:
1818
- name: Checkout code

.github/workflows/release-please.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
env:
3333
FLUTTER_CHANNEL: stable
34-
FLUTTER_VERSION: 3.22.2
34+
FLUTTER_VERSION: 3.27.3
3535
if: ${{ needs.release-please.outputs.release_created }}
3636
steps:
3737
- uses: actions/checkout@v4

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Do not remove or rename entries in this file, only add new ones
22
# See https://github.com/flutter/flutter/issues/128635 for more context.
33

4+
example/.env
5+
46
# Miscellaneous
57
*.class
68
*.lock

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ android {
5151

5252
dependencies {
5353
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
54-
implementation("com.spotify.confidence:confidence-sdk-android:0.3.2")
54+
implementation("com.spotify.confidence:confidence-sdk-android:0.3.6")
5555
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.0") // force this to 1.9.0
5656
testImplementation("org.jetbrains.kotlin:kotlin-test")
5757
testImplementation("org.mockito:mockito-core:5.1.0")

android/src/main/kotlin/com/example/confidence_flutter_sdk/ConfidenceFlutterSdkPlugin.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.spotify.confidence.Confidence
55
import com.spotify.confidence.ConfidenceFactory
66
import com.spotify.confidence.ConfidenceValue
7+
import com.spotify.confidence.LoggingLevel
78
import com.spotify.confidence.FlagResolution
89
import com.spotify.confidence.client.SdkMetadata
910
import io.flutter.embedding.engine.plugins.FlutterPlugin
@@ -41,11 +42,12 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
4142
confidence.flush()
4243
}
4344
"setup" -> {
44-
val apiKey = call.arguments as String
45+
val apiKey = call.argument<String>("apiKey")!!
46+
val loggingLevel = call.argument<String>("loggingLevel")!!
4547
confidence = ConfidenceFactory.create(
4648
context,
4749
apiKey,
48-
sdk = SdkMetadata("SDK_ID_FLUTTER_ANDROID_CONFIDENCE", "0.0.1")
50+
loggingLevel = LoggingLevel.valueOf(loggingLevel)
4951
)
5052
result.success(null)
5153
}

example/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

example/android/app/build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ android {
2929
ndkVersion = flutter.ndkVersion
3030

3131
compileOptions {
32-
sourceCompatibility = JavaVersion.VERSION_1_8
33-
targetCompatibility = JavaVersion.VERSION_1_8
32+
sourceCompatibility = JavaVersion.VERSION_17
33+
targetCompatibility = JavaVersion.VERSION_17
3434
}
3535

3636
defaultConfig {
@@ -48,6 +48,8 @@ android {
4848
// TODO: Add your own signing config for the release build.
4949
// Signing with the debug keys for now, so `flutter run --release` works.
5050
signingConfig = signingConfigs.debug
51+
shrinkResources = false
52+
minifyEnabled = false
5153
}
5254
}
5355
}

example/android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

example/android/settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "7.3.0" apply false
21+
id "com.android.application" version "8.1.0" apply false
2222
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
2323
}
2424

example/ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '12.0'
2+
platform :ios, '17.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Runner/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Flutter
22
import UIKit
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

example/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _MyAppState extends State<MyApp> {
4444
// We also handle the message potentially returning null.
4545
try {
4646
await dotenv.load(fileName: ".env");
47-
await _confidenceFlutterSdkPlugin.setup(dotenv.env["API_KEY"]!);
47+
await _confidenceFlutterSdkPlugin.setup(dotenv.env["API_KEY"]!, LoggingLevel.VERBOSE);
4848
await _confidenceFlutterSdkPlugin.putAllContext({
4949
"targeting_key": "random",
5050
"my_bool": false,

ios/Classes/ConfidenceFlutterSdkPlugin.swift

+25-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
3434
result(str)
3535
break;
3636
case "setup":
37-
let apiKey = call.arguments as! String
38-
self.confidence = Confidence.Builder(clientSecret: apiKey)
37+
guard let args = call.arguments as? Dictionary<String, Any> else {
38+
result("")
39+
return
40+
}
41+
let apiKey = args["apiKey"] as! String
42+
let logLevel = args["loggingLevel"] as! String
43+
self.confidence = Confidence.Builder(clientSecret: apiKey, loggerLevel: loggerLevel(from: logLevel))
3944
.build()
4045
result("")
4146
break;
@@ -63,7 +68,9 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
6368
return
6469
}
6570
try! confidence.activate()
66-
confidence.asyncFetch()
71+
Task {
72+
await confidence.asyncFetch()
73+
}
6774
result("")
6875
}
6976
break;
@@ -169,6 +176,21 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
169176
result(FlutterMethodNotImplemented)
170177
}
171178
}
179+
180+
func loggerLevel(from string: String) -> LoggerLevel {
181+
switch string.uppercased() {
182+
case "VERBOSE":
183+
return .TRACE
184+
case "DEBUG":
185+
return .DEBUG
186+
case "WARN":
187+
return .WARN
188+
case "ERROR":
189+
return .ERROR
190+
default:
191+
return .WARN
192+
}
193+
}
172194
}
173195

174196
func readAllFlags() throws -> [ResolvedValue] {

lib/confidence_flutter_sdk.dart

+10-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class ConfidenceFlutterSdk {
9090
return resolveKey(key) ?? defaultValue;
9191
}
9292

93-
Future<void> setup(String apiKey) async {
94-
return await ConfidenceFlutterSdkPlatform.instance.setup(apiKey);
93+
Future<void> setup(String apiKey, [LoggingLevel loggingLevel = LoggingLevel.WARN]) async {
94+
return await ConfidenceFlutterSdkPlatform.instance.setup(apiKey, loggingLevel);
9595
}
9696

9797
Future<void> fetchAndActivate() async {
@@ -109,3 +109,11 @@ class ConfidenceFlutterSdk {
109109
await fillAllFlags();
110110
}
111111
}
112+
113+
enum LoggingLevel {
114+
VERBOSE, // 0
115+
DEBUG, // 1
116+
WARN, // 2
117+
ERROR, // 3
118+
NONE // 4
119+
}

lib/confidence_flutter_sdk_method_channel.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:confidence_flutter_sdk/confidence_flutter_sdk.dart';
12
import 'package:flutter/foundation.dart';
23
import 'package:flutter/services.dart';
34
import 'dart:convert';
@@ -11,8 +12,8 @@ class MethodChannelConfidenceFlutterSdk extends ConfidenceFlutterSdkPlatform {
1112
final methodChannel = const MethodChannel('confidence_flutter_sdk');
1213

1314
@override
14-
Future<void> setup(String apiKey) async {
15-
return await methodChannel.invokeMethod<void>('setup', apiKey);
15+
Future<void> setup(String apiKey, LoggingLevel loggingLevel) async {
16+
return await methodChannel.invokeMethod<void>('setup', {'apiKey': apiKey, 'loggingLevel': loggingLevel.name});
1617
}
1718

1819
@override

lib/confidence_flutter_sdk_platform_interface.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:confidence_flutter_sdk/confidence_flutter_sdk.dart';
12
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
23

34
import 'confidence_flutter_sdk_method_channel.dart';
@@ -23,7 +24,7 @@ abstract class ConfidenceFlutterSdkPlatform extends PlatformInterface {
2324
_instance = instance;
2425
}
2526

26-
Future<void> setup(String apiKey) {
27+
Future<void> setup(String apiKey, LoggingLevel loggingLevel) {
2728
throw UnimplementedError('setup() has not been implemented.');
2829
}
2930

0 commit comments

Comments
 (0)