Use custom flutter LogLevels from Android

This commit is contained in:
Adam Velebil 2022-05-06 17:45:34 +02:00
parent ce78d7a25a
commit 8328f76b46
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
2 changed files with 26 additions and 12 deletions

View File

@ -62,7 +62,8 @@ class MainActivity : FlutterFragmentActivity() {
}
override fun logDebug(message: String) {
FlutterLog.d(message)
// redirect yubikit debug logs to flutter traffic
FlutterLog.t(message)
}
override fun logError(message: String, throwable: Throwable) {

View File

@ -1,20 +1,12 @@
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
import '../app/logging.dart';
class AndroidLogger {
final _androidLogger = Logger('android.redirect');
final MethodChannel _channel = const MethodChannel('android.log.redirect');
final levelMap = <String, Level>{
't': Level.FINE,
'd': Level.CONFIG,
'i': Level.INFO,
'w': Level.WARNING,
'e': Level.SEVERE,
'wtf': Level.SHOUT,
'v': Level.ALL,
};
static AndroidLogger? instance;
static void initialize() {
instance = AndroidLogger();
@ -25,7 +17,28 @@ class AndroidLogger {
var level = call.arguments['level'];
var message = call.arguments['message'];
var error = call.arguments['error'];
_androidLogger.log(levelMap[level] ?? Level.INFO, message, error);
switch (level) {
case 't':
case 'v':
_androidLogger.traffic(message, error);
break;
case 'd':
_androidLogger.debug(message, error);
break;
case 'w':
_androidLogger.warning(message, error);
break;
case 'e':
case 'wtf':
_androidLogger.error(message, error);
break;
case 'i':
default:
_androidLogger.info(message, error);
break;
}
return 0;
});
}