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:
@@ -35,8 +35,8 @@ abstract final class MethodChans {
|
||||
try {
|
||||
Loggers.app.info('Updating Android sessions: $payload');
|
||||
await _channel.invokeMethod('updateSessions', payload);
|
||||
} catch (_) {
|
||||
// ignore
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to update Android sessions', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ abstract final class MethodChans {
|
||||
try {
|
||||
final res = await _channel.invokeMethod('isServiceRunning');
|
||||
return res == true;
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to check if Android service is running', e, s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +58,9 @@ abstract final class MethodChans {
|
||||
try {
|
||||
Loggers.app.info('Starting iOS Live Activity: $payload');
|
||||
await _channel.invokeMethod('startLiveActivity', payload);
|
||||
} catch (_) {}
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to start iOS Live Activity', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> updateLiveActivity(String payload) async {
|
||||
@@ -65,7 +68,9 @@ abstract final class MethodChans {
|
||||
try {
|
||||
Loggers.app.info('Updating iOS Live Activity: $payload');
|
||||
await _channel.invokeMethod('updateLiveActivity', payload);
|
||||
} catch (_) {}
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to update iOS Live Activity', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> stopLiveActivity() async {
|
||||
@@ -73,7 +78,9 @@ abstract final class MethodChans {
|
||||
try {
|
||||
Loggers.app.info('Stopping iOS Live Activity');
|
||||
await _channel.invokeMethod('stopLiveActivity');
|
||||
} catch (_) {}
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to stop iOS Live Activity', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
/// Register a handler for native -> Flutter callbacks.
|
||||
|
||||
@@ -74,7 +74,8 @@ class SshDiscoveryService {
|
||||
// Some tools return non-zero but still have useful output
|
||||
if (out.trim().isNotEmpty) return out;
|
||||
return null;
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to run command: $exe ${args.join(' ')}', e, s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +110,7 @@ class SshDiscoveryService {
|
||||
}
|
||||
}
|
||||
if (matchCount == 0) {
|
||||
lprint(
|
||||
Loggers.app.warning(
|
||||
'[ssh_discovery] Warning: No ARP entries parsed on macOS. Output may be unexpected or localized. Output sample: ${s.length > 100 ? '${s.substring(0, 100)}...' : s}',
|
||||
);
|
||||
}
|
||||
@@ -176,8 +177,7 @@ class SshDiscoveryService {
|
||||
r'inet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+0x([0-9a-fA-F]+)(?:\s+broadcast\s+(\d+\.\d+\.\d+\.\d+))?',
|
||||
).firstMatch(line);
|
||||
if (ipm == null) {
|
||||
// Log unexpected format but continue processing other lines
|
||||
lprint('[ssh_discovery] Warning: Unexpected ifconfig line format: $line');
|
||||
Loggers.app.warning('[ssh_discovery] Warning: Unexpected ifconfig line format: $line');
|
||||
continue;
|
||||
}
|
||||
final ip = InternetAddress(ipm.group(1)!);
|
||||
@@ -190,7 +190,7 @@ class SshDiscoveryService {
|
||||
final brd = InternetAddress(ipm.group(3) ?? _broadcastAddress(ip, mask).address);
|
||||
res.add(_Cidr(ip, prefix, mask, net, brd));
|
||||
} catch (e) {
|
||||
lprint('[ssh_discovery] Error parsing ifconfig output: $e, line: $line');
|
||||
Loggers.app.warning('[ssh_discovery] Error parsing ifconfig output: $e, line: $line');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,9 @@ class SshDiscoveryService {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to discover mDNS SSH candidates on macOS', e, s);
|
||||
}
|
||||
} else if (_isLinux) {
|
||||
final s = await _run('/usr/bin/avahi-browse', ['-rat', '_ssh._tcp']);
|
||||
if (s != null) {
|
||||
@@ -335,7 +337,8 @@ class _Scanner {
|
||||
);
|
||||
final banner = await c.future.timeout(timeout, onTimeout: () => null);
|
||||
return _ScanResult(ip, banner);
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to probe SSH at ${ip.address}', e, s);
|
||||
return null;
|
||||
} finally {
|
||||
sub?.cancel();
|
||||
|
||||
@@ -26,7 +26,8 @@ final class BakSyncer extends SyncIface {
|
||||
return MergeableUtils.fromJsonString(content, pwd).$1;
|
||||
}
|
||||
return MergeableUtils.fromJsonString(content).$1;
|
||||
} catch (_) {
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('Failed to parse backup file with password, trying without password', e, s);
|
||||
// Fallback: try without password if detection failed
|
||||
return MergeableUtils.fromJsonString(content).$1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user