mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +03:00
avoid depending on flutter log level value
This commit is contained in:
parent
99708c99ef
commit
b0a1d16012
@ -6,23 +6,18 @@ import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class FlutterLog(messenger: BinaryMessenger) {
|
||||
|
||||
private enum class LogLevel(val value: Int) {
|
||||
TRAFFIC(500),
|
||||
DEBUG(700),
|
||||
INFO(800),
|
||||
WARNING(900),
|
||||
ERROR(1000);
|
||||
|
||||
companion object {
|
||||
fun fromInt(value: Int?) = values().firstOrNull { it.value == value }
|
||||
}
|
||||
private enum class LogLevel {
|
||||
TRAFFIC,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
|
||||
private var _channel = MethodChannel(messenger, "android.log.redirect")
|
||||
private var _level = LogLevel.INFO
|
||||
|
||||
companion object {
|
||||
|
||||
private const val TAG = "yubico-authenticator"
|
||||
|
||||
private lateinit var instance: FlutterLog
|
||||
@ -31,6 +26,10 @@ class FlutterLog(messenger: BinaryMessenger) {
|
||||
instance = FlutterLog(messenger)
|
||||
}
|
||||
|
||||
private val logLevelFromArgument: (String?) -> LogLevel = { argValue ->
|
||||
LogLevel.valueOf(argValue?.uppercase() ?: "INFO")
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun t(tag: String, message: String, error: String? = null) {
|
||||
instance.log(LogLevel.TRAFFIC, tag, message, error)
|
||||
@ -59,14 +58,15 @@ class FlutterLog(messenger: BinaryMessenger) {
|
||||
|
||||
init {
|
||||
_channel.setMethodCallHandler { call, result ->
|
||||
|
||||
when (call.method) {
|
||||
"log" -> {
|
||||
val message = call.argument<String>("message")
|
||||
val error = call.argument<String?>("error")
|
||||
val loggerName = call.argument<String>("loggerName")
|
||||
val level = LogLevel.fromInt(call.argument<Int>("level"))
|
||||
val level = logLevelFromArgument(call.argument("level"))
|
||||
|
||||
if (level != null && loggerName != null && message != null) {
|
||||
if (loggerName != null && message != null) {
|
||||
log(level, loggerName, message, error)
|
||||
result.success(null)
|
||||
} else {
|
||||
@ -74,11 +74,9 @@ class FlutterLog(messenger: BinaryMessenger) {
|
||||
}
|
||||
}
|
||||
"setLevel" -> {
|
||||
_level = LogLevel.fromInt(call.argument<Int>("level")) ?: LogLevel.INFO
|
||||
_level = logLevelFromArgument(call.argument("level"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,14 @@ class AndroidLogger {
|
||||
|
||||
void setLogLevel(Level level) async {
|
||||
await _channel.invokeMethod('setLevel', {
|
||||
'level': level.value,
|
||||
'level': level.name,
|
||||
});
|
||||
}
|
||||
|
||||
void log(LogRecord record) async {
|
||||
await _channel.invokeMethod('log', {
|
||||
'loggerName': record.loggerName,
|
||||
'level': record.level.value,
|
||||
'level': record.level.name,
|
||||
'message': record.message,
|
||||
'error': record.error
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user