mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-22 17:51:29 +03:00
Support changing log level.
This commit is contained in:
parent
064fb038e6
commit
e439acdce6
@ -42,20 +42,13 @@ class _Request {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Level _forPythonName(String name) {
|
const _py2level = {
|
||||||
switch (name) {
|
'DEBUG': Level.CONFIG,
|
||||||
case 'DEBUG':
|
'INFO': Level.INFO,
|
||||||
return Level.CONFIG;
|
'WARNING': Level.WARNING,
|
||||||
case 'INFO':
|
'ERROR': Level.SEVERE,
|
||||||
return Level.INFO;
|
'CRITICAL': Level.SHOUT,
|
||||||
case 'WARNING':
|
};
|
||||||
return Level.WARNING;
|
|
||||||
case 'ERROR':
|
|
||||||
return Level.SEVERE;
|
|
||||||
default:
|
|
||||||
return Level.INFO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RpcSession {
|
class RpcSession {
|
||||||
final Process _process;
|
final Process _process;
|
||||||
@ -73,7 +66,7 @@ class RpcSession {
|
|||||||
.map((event) => jsonDecode(event))
|
.map((event) => jsonDecode(event))
|
||||||
.listen((event) {
|
.listen((event) {
|
||||||
Logger('rpc.${event['name']}').log(
|
Logger('rpc.${event['name']}').log(
|
||||||
_forPythonName(event['level']),
|
_py2level[event['level']] ?? Level.INFO,
|
||||||
event['message'],
|
event['message'],
|
||||||
//time: DateTime.fromMillisecondsSinceEpoch(event['time'] * 1000),
|
//time: DateTime.fromMillisecondsSinceEpoch(event['time'] * 1000),
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'models.dart';
|
import 'models.dart';
|
||||||
@ -14,6 +15,21 @@ final rpcProvider = Provider<RpcSession>((ref) {
|
|||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
final logLevelProvider = StateNotifierProvider<LogLevelNotifier, Level>(
|
||||||
|
(ref) => LogLevelNotifier(ref.watch(rpcProvider), Logger.root.level));
|
||||||
|
|
||||||
|
class LogLevelNotifier extends StateNotifier<Level> {
|
||||||
|
final RpcSession rpc;
|
||||||
|
LogLevelNotifier(this.rpc, Level state) : super(state);
|
||||||
|
|
||||||
|
setLevel(Level level) {
|
||||||
|
Logger.root.level = level;
|
||||||
|
rpc.setLogLevel(level);
|
||||||
|
state = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class RpcNodeSession {
|
class RpcNodeSession {
|
||||||
final RpcSession _rpc;
|
final RpcSession _rpc;
|
||||||
final List<String> devicePath;
|
final List<String> devicePath;
|
||||||
|
@ -60,7 +60,7 @@ void _initLogging(Level level, RpcSession rpc) {
|
|||||||
//TODO: Add support for logging to stderr and file
|
//TODO: Add support for logging to stderr and file
|
||||||
Logger.root.onRecord.listen((record) {
|
Logger.root.onRecord.listen((record) {
|
||||||
developer.log(
|
developer.log(
|
||||||
'${record.level} ${record.message}',
|
'${record.level}: ${record.message}',
|
||||||
error: record.error,
|
error: record.error,
|
||||||
name: record.loggerName,
|
name: record.loggerName,
|
||||||
time: record.time,
|
time: record.time,
|
||||||
|
18
pubspec.lock
18
pubspec.lock
@ -63,7 +63,7 @@ packages:
|
|||||||
name: build_resolvers
|
name: build_resolvers
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.4"
|
version: "2.0.5"
|
||||||
build_runner:
|
build_runner:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -421,6 +421,20 @@ packages:
|
|||||||
name: shared_preferences
|
name: shared_preferences
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
|
version: "2.0.9"
|
||||||
|
shared_preferences_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_android
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.9"
|
||||||
|
shared_preferences_ios:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_ios
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
version: "2.0.8"
|
version: "2.0.8"
|
||||||
shared_preferences_linux:
|
shared_preferences_linux:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
@ -587,7 +601,7 @@ packages:
|
|||||||
name: win32
|
name: win32
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.3.0"
|
version: "2.3.1"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 318b0981d545950a45a8c9b9e17de9332e1f64b5
|
Subproject commit 87480b6cfffeda8ac7f25c3f60d3cc0bb11acd0a
|
Loading…
Reference in New Issue
Block a user