fix(log): Logging System Improvements and Error Handling Enhancements (#994)

* fix: Added logging to exception handling

Added detailed error logging to exception handling across multiple files, including exception information and stack traces, to facilitate troubleshooting.

* refactor(logging): Standardize logging output methods

Replace existing debugPrint and lprint with Loggers.app.warning to enhance logging consistency and maintainability.

* refactor: Remove redundant debug log prints

Clean up unnecessary log print statements in debug code

* feat(i18n): Added internationalization support for the logging feature
This commit is contained in:
GT610
2026-01-07 15:09:22 +08:00
committed by GitHub
parent cc300c141a
commit 2c495a44c3
36 changed files with 114 additions and 41 deletions

View File

@@ -74,8 +74,8 @@ class BackupService {
await _confirmAndRestore(context, backup);
return;
}
} catch (e) {
// Saved password failed, will prompt for manual input
} catch (e, s) {
Loggers.app.warning('Failed to restore with saved password, will prompt for manual input', e, s);
}
}

View File

@@ -164,7 +164,8 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
final bytesIn = BigInt.parse(bytes.first);
final bytesOut = BigInt.parse(bytes[8]);
results.add(NetSpeedPart(device, bytesIn, bytesOut, time));
} catch (_) {
} catch (e, s) {
Loggers.app.warning('Failed to parse net speed data: $item', e, s);
continue;
}
}

View File

@@ -679,7 +679,7 @@ void _parseWindowsTemperatures(Temperatures temps, String raw) {
if (typeLines.isNotEmpty && valueLines.isNotEmpty) {
temps.parse(typeLines.join('\n'), valueLines.join('\n'));
}
} catch (e) {
// If JSON parsing fails, ignore temperature data
} catch (e, s) {
Loggers.app.warning('Failed to parse Windows temperature data', e, s);
}
}

View File

@@ -21,7 +21,8 @@ class SftpReq {
}
try {
knownHostFingerprints = Map<String, String>.from(Stores.setting.sshKnownHostFingerprints.get());
} catch (_) {
} catch (e, s) {
Loggers.app.warning('Failed to load SSH known host fingerprints', e, s);
knownHostFingerprints = null;
}
}

View File

@@ -6,7 +6,6 @@ import 'package:dartssh2/dartssh2.dart';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:server_box/core/extension/context/locale.dart';
@@ -108,7 +107,7 @@ class PveNotifier extends _$PveNotifier {
final newUrl = Uri.parse(
addr,
).replace(host: 'localhost', port: _localPort).toString();
debugPrint('Forwarding $newUrl to $addr');
dprint('Forwarding $newUrl to $addr');
}
}
@@ -235,11 +234,15 @@ class PveNotifier extends _$PveNotifier {
Future<void> dispose() async {
try {
await _serverSocket.close();
} catch (_) {}
} catch (e, s) {
Loggers.app.warning('Failed to close server socket', e, s);
}
for (final forward in _forwards) {
try {
forward.close();
} catch (_) {}
} catch (e, s) {
Loggers.app.warning('Failed to close forward', e, s);
}
}
}
}