Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Last active April 22, 2018 09:55
Show Gist options
  • Save ponnamkarthik/94e47e4cdaa6de20633ceaba96cc0042 to your computer and use it in GitHub Desktop.
Save ponnamkarthik/94e47e4cdaa6de20633ceaba96cc0042 to your computer and use it in GitHub Desktop.
FlutterNativeLogPlugin.kt
package io.github.ponnamkarthik.flutternativelog
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.PluginRegistry.Registrar
import android.util.Log
class FlutterNativeLogPlugin(): MethodCallHandler {
companion object {
@JvmStatic
fun registerWith(registrar: Registrar): Unit {
val channel = MethodChannel(registrar.messenger(), "flutter_native_log")
channel.setMethodCallHandler(FlutterNativeLogPlugin())
}
}
override fun onMethodCall(call: MethodCall, result: Result): Unit {
if (call.method.equals("getPlatformVersion")) {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else if(call.method.equals("printLog")){
val msg: String = call.argument("msg")
val tag: String = call.argument("tag")
val logType: String = call.argument("logType")
if(logType.equals("warning")) {
Log.w(tag, msg)
} else if(logType.equals("error")) {
Log.e(tag, msg)
} else {
Log.d(tag, msg)
}
result.success("Logged Successfully!")
} else {
result.notImplemented()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment