diff --git a/fimber_io/.gitignore b/fimber_io/.gitignore index 50602ac..ad8332d 100644 --- a/fimber_io/.gitignore +++ b/fimber_io/.gitignore @@ -9,3 +9,8 @@ build/ # Directory created by dartdoc doc/api/ + +# file generated by the example +test.log +# folder generated by the tests +test_logs/ diff --git a/flutter_fimber/android/src/main/kotlin/com/magillus/flutter_fimber/FlutterFimberPlugin.kt b/flutter_fimber/android/src/main/kotlin/com/magillus/flutter_fimber/FlutterFimberPlugin.kt index a7a4d26..e58f4cf 100644 --- a/flutter_fimber/android/src/main/kotlin/com/magillus/flutter_fimber/FlutterFimberPlugin.kt +++ b/flutter_fimber/android/src/main/kotlin/com/magillus/flutter_fimber/FlutterFimberPlugin.kt @@ -1,7 +1,6 @@ package com.magillus.flutter_fimber -import androidx.annotation.NonNull - +import android.util.Log import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel @@ -16,20 +15,38 @@ class FlutterFimberPlugin: FlutterPlugin, MethodCallHandler { /// when the Flutter Engine is detached from the Activity private lateinit var channel : MethodChannel - override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_fimber") channel.setMethodCallHandler(this) } - override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { - if (call.method == "getPlatformVersion") { - result.success("Android ${android.os.Build.VERSION.RELEASE}") - } else { - result.notImplemented() + override fun onMethodCall(call: MethodCall, result: Result) { + when (call.method) { + "getPlatformVersion" -> result.success("Android ${android.os.Build.VERSION.RELEASE}") + "log" -> log(call, result) + else -> result.notImplemented() } } - override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) } + + private fun log(call: MethodCall, result: Result) { + val tag = call.argument("tag") ?: "flutter" + val message = call.argument("message") ?: "" + val level = call.argument("level") ?: "V" + val throwable = call.argument("ex")?.let { Throwable(it) } + + when (level) { + "V" -> Log.v(tag, message, throwable) + "D" -> Log.d(tag, message, throwable) + "I" -> Log.i(tag, message, throwable) + "W" -> Log.w(tag, message, throwable) + "E" -> Log.e(tag, message, throwable) + "WTF" -> Log.wtf(tag, message, throwable) + else -> Log.d(tag, message, throwable) + } + result.success(null) + } } diff --git a/flutter_fimber/example/android/app/src/main/AndroidManifest.xml b/flutter_fimber/example/android/app/src/main/AndroidManifest.xml index b11893f..8b8d158 100644 --- a/flutter_fimber/example/android/app/src/main/AndroidManifest.xml +++ b/flutter_fimber/example/android/app/src/main/AndroidManifest.xml @@ -22,7 +22,6 @@ android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" - android:exported="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> diff --git a/flutter_fimber/example/android/build.gradle b/flutter_fimber/example/android/build.gradle index d031eb2..4b30292 100644 --- a/flutter_fimber/example/android/build.gradle +++ b/flutter_fimber/example/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/flutter_fimber/example/lib/main.dart b/flutter_fimber/example/lib/main.dart index ef77359..c325aa1 100644 --- a/flutter_fimber/example/lib/main.dart +++ b/flutter_fimber/example/lib/main.dart @@ -82,7 +82,7 @@ class _MyAppState extends State { onPressed: () { try { throw AssertionError(); - } on Exception catch (e, s) { + } on AssertionError catch (e, s) { Fimber.w("Warning message test ${DateTime.now()}", ex: e, stacktrace: s); }