Fix "--log-level" argument which wasn't working correctly.

This commit is contained in:
Dain Nilsson 2022-04-29 14:41:40 +02:00
parent 10f46ec478
commit 51a76f686d
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
3 changed files with 8 additions and 9 deletions

View File

@ -45,7 +45,7 @@ void main() {
testWidgets('Add account', (WidgetTester tester) async {
final Widget initializedApp;
if (isDesktop) {
initializedApp = await desktop.initialize();
initializedApp = await desktop.initialize([]);
} else if (isAndroid) {
initializedApp = await android.initialize();
} else {

View File

@ -39,8 +39,8 @@ class _WindowResizeListener extends WindowListener {
}
}
Future<Widget> initialize() async {
_initLogging();
Future<Widget> initialize(List<String> argv) async {
_initLogging(argv);
await windowManager.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
@ -107,7 +107,7 @@ Future<Widget> initialize() async {
);
}
void _initLogging() {
void _initLogging(List<String> argv) {
Logger.root.onRecord.listen((record) {
stderr.writeln('[${record.loggerName}] ${record.level}: ${record.message}');
if (record.error != null) {
@ -115,11 +115,10 @@ void _initLogging() {
}
});
final arguments = Platform.executableArguments;
final logLevelIndex = arguments.indexOf('--log-level');
final logLevelIndex = argv.indexOf('--log-level');
if (logLevelIndex != -1) {
try {
final levelName = arguments[logLevelIndex + 1];
final levelName = argv[logLevelIndex + 1];
Level level = Level.LEVELS
.firstWhere((level) => level.name == levelName.toUpperCase());
Logger.root.level = level;

View File

@ -13,13 +13,13 @@ import 'error_page.dart';
final _log = Logger('main');
void main() async {
void main(List<String> argv) async {
WidgetsFlutterBinding.ensureInitialized();
try {
final Widget initializedApp;
if (isDesktop) {
initializedApp = await desktop.initialize();
initializedApp = await desktop.initialize(argv);
} else if (isAndroid) {
initializedApp = await android.initialize();
} else {