mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-02 16:20:57 +02:00
chore(logging): sanitize diagnostics and reduce noise
This commit is contained in:
@@ -2,8 +2,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Widest content span for a surface of [maxWidth]: content is never narrower
|
||||
/// than [contentMaxWidth], and the centering margin never exceeds 80dp per
|
||||
/// side — so tablets keep near-full-width rows (issue #493) instead of a
|
||||
/// fixed 720dp column floating in whitespace.
|
||||
/// side so tablets retain near-full-width rows.
|
||||
double adaptiveContentMaxWidth(
|
||||
double maxWidth, {
|
||||
double contentMaxWidth = 720,
|
||||
|
||||
+24
-4
@@ -8,6 +8,7 @@ import 'package:spotiflac_android/constants/app_info.dart';
|
||||
import 'package:spotiflac_android/services/platform_bridge.dart';
|
||||
|
||||
const int _maxLogMessageLength = 500;
|
||||
const int _maxBufferedLogMessageLength = 4000;
|
||||
const String _redactedValue = '[REDACTED]';
|
||||
|
||||
final RegExp _authorizationBearerPattern = RegExp(
|
||||
@@ -16,7 +17,7 @@ final RegExp _authorizationBearerPattern = RegExp(
|
||||
);
|
||||
|
||||
final RegExp _genericSensitiveKeyValuePattern = RegExp(
|
||||
r'("?(?:access[_\s-]?token|refresh[_\s-]?token|id[_\s-]?token|client[_\s-]?secret|authorization|password|api[_\s-]?key|session[_\s-]?secret|cookie|set-cookie)"?)(\s*[:=]\s*)("(?:\\.|[^"\\])*"|[^\s,;}\]]+)',
|
||||
r'("?(?:access[_\s-]?token|refresh[_\s-]?token|id[_\s-]?token|client[_\s-]?secret|authorization|password|api[_\s-]?key|session[_\s-]?secret|decryption[_\s-]?key|cookie|set-cookie)"?)(\s*[:=]\s*)("(?:\\.|[^"\\])*"|[^\s,;}\]]+)',
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
@@ -30,6 +31,11 @@ final RegExp _bearerTokenPattern = RegExp(
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
final RegExp _decryptionKeyFlagPattern = RegExp(
|
||||
r'(-decryption_key\s+)[^\s]+',
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
String _truncateLogText(String value, {int maxLength = _maxLogMessageLength}) {
|
||||
if (value.length <= maxLength) {
|
||||
return value;
|
||||
@@ -61,6 +67,10 @@ String _redactSensitiveText(String value) {
|
||||
return 'Bearer $_redactedValue';
|
||||
});
|
||||
|
||||
redacted = redacted.replaceAllMapped(_decryptionKeyFlagPattern, (match) {
|
||||
return '${match.group(1) ?? '-decryption_key '}$_redactedValue';
|
||||
});
|
||||
|
||||
return redacted;
|
||||
}
|
||||
|
||||
@@ -136,9 +146,15 @@ class LogBuffer extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
|
||||
final sanitizedMessage = _redactSensitiveText(entry.message);
|
||||
final sanitizedMessage = _truncateLogText(
|
||||
_redactSensitiveText(entry.message),
|
||||
maxLength: _maxBufferedLogMessageLength,
|
||||
);
|
||||
final sanitizedError = entry.error != null
|
||||
? _redactSensitiveText(entry.error!)
|
||||
? _truncateLogText(
|
||||
_redactSensitiveText(entry.error!),
|
||||
maxLength: _maxBufferedLogMessageLength,
|
||||
)
|
||||
: null;
|
||||
final sanitizedEntry =
|
||||
(sanitizedMessage == entry.message && sanitizedError == entry.error)
|
||||
@@ -380,7 +396,11 @@ class BufferedOutput extends LogOutput {
|
||||
|
||||
@override
|
||||
void output(OutputEvent event) {
|
||||
if (kDebugMode) {
|
||||
if (kDebugMode &&
|
||||
(LogBuffer.loggingEnabled ||
|
||||
event.level == Level.warning ||
|
||||
event.level == Level.error ||
|
||||
event.level == Level.fatal)) {
|
||||
for (final line in event.lines) {
|
||||
debugPrint(_truncateLogText(_redactSensitiveText(line)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user