TF-4136 refactor(logging): replace logError with logWarning for non-critical cases
This commit is contained in:
@@ -16,7 +16,7 @@ const appLogName = '[TwakeMail]';
|
||||
|
||||
String _applyWebColor(Level level, String text) {
|
||||
switch (level) {
|
||||
case Level.wtf:
|
||||
case Level.critical:
|
||||
return '$ansiRed$ansiBold!!!CRITICAL!!! $text$ansiReset';
|
||||
case Level.error:
|
||||
return '$ansiRed$text$ansiReset';
|
||||
@@ -26,14 +26,14 @@ String _applyWebColor(Level level, String text) {
|
||||
return '$ansiGreen$text$ansiReset';
|
||||
case Level.debug:
|
||||
return '$ansiBlue$text$ansiReset';
|
||||
case Level.verbose:
|
||||
case Level.trace:
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
String _applyMobileFormat(Level level, String text) {
|
||||
switch (level) {
|
||||
case Level.wtf:
|
||||
case Level.critical:
|
||||
return '🔥 CRITICAL: $text';
|
||||
case Level.error:
|
||||
return '❌ ERROR: $text';
|
||||
@@ -43,7 +43,7 @@ String _applyMobileFormat(Level level, String text) {
|
||||
return 'ℹ️ INFO: $text';
|
||||
case Level.debug:
|
||||
return '🐛 DEBUG: $text';
|
||||
case Level.verbose:
|
||||
case Level.trace:
|
||||
return '🔍 VERBOSE: $text';
|
||||
}
|
||||
}
|
||||
@@ -56,13 +56,22 @@ void _internalLog(
|
||||
Map<String, dynamic>? extras,
|
||||
bool webConsoleEnabled = false,
|
||||
}) {
|
||||
final shouldPrint = webConsoleEnabled
|
||||
? PlatformInfo.isWeb
|
||||
: BuildUtils.isDebugMode;
|
||||
|
||||
if (!shouldPrint) {
|
||||
return;
|
||||
}
|
||||
|
||||
final rawMessage = _buildRawMessage(message, exception, extras, stackTrace);
|
||||
final formattedMessage = _formatMessage(level, rawMessage);
|
||||
|
||||
if (webConsoleEnabled && PlatformInfo.isWeb) {
|
||||
_printWebConsole(level, formattedMessage);
|
||||
} else {
|
||||
_debugPrint(formattedMessage);
|
||||
// ignore: avoid_print
|
||||
print('$appLogName $formattedMessage');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,24 +89,16 @@ String _buildRawMessage(
|
||||
return parts.join(' | ');
|
||||
}
|
||||
|
||||
|
||||
String _formatMessage(Level level, String raw) {
|
||||
return PlatformInfo.isWeb
|
||||
? _applyWebColor(level, raw)
|
||||
: _applyMobileFormat(level, raw);
|
||||
}
|
||||
|
||||
void _debugPrint(String formatted) {
|
||||
if (!BuildUtils.isDebugMode) return;
|
||||
|
||||
// ignore: avoid_print
|
||||
print('$appLogName $formatted');
|
||||
}
|
||||
|
||||
void _printWebConsole(Level level, String value) {
|
||||
switch (level) {
|
||||
case Level.error:
|
||||
case Level.wtf:
|
||||
case Level.critical:
|
||||
html.window.console.error('$appLogName $value');
|
||||
break;
|
||||
case Level.warning:
|
||||
@@ -107,7 +108,7 @@ void _printWebConsole(Level level, String value) {
|
||||
html.window.console.info('$appLogName $value');
|
||||
break;
|
||||
case Level.debug:
|
||||
case Level.verbose:
|
||||
case Level.trace:
|
||||
html.window.console.debug('$appLogName $value');
|
||||
break;
|
||||
}
|
||||
@@ -130,7 +131,7 @@ void logError(
|
||||
);
|
||||
}
|
||||
|
||||
void logWTF(
|
||||
void logCritical(
|
||||
String? message, {
|
||||
Object? exception,
|
||||
StackTrace? stackTrace,
|
||||
@@ -139,7 +140,7 @@ void logWTF(
|
||||
}) {
|
||||
_internalLog(
|
||||
message,
|
||||
level: Level.wtf,
|
||||
level: Level.critical,
|
||||
exception: exception,
|
||||
stackTrace: stackTrace,
|
||||
extras: extras,
|
||||
@@ -177,13 +178,13 @@ void logDebug(
|
||||
);
|
||||
}
|
||||
|
||||
void logVerbose(
|
||||
void logTrace(
|
||||
String? message, {
|
||||
bool webConsoleEnabled = false,
|
||||
}) {
|
||||
_internalLog(
|
||||
message,
|
||||
level: Level.verbose,
|
||||
level: Level.trace,
|
||||
webConsoleEnabled: webConsoleEnabled,
|
||||
);
|
||||
}
|
||||
@@ -198,12 +199,12 @@ void log(
|
||||
);
|
||||
|
||||
enum Level {
|
||||
wtf,
|
||||
critical,
|
||||
error,
|
||||
warning,
|
||||
info,
|
||||
debug,
|
||||
verbose,
|
||||
trace,
|
||||
}
|
||||
|
||||
// Take from: https://flutter.dev/docs/testing/errors
|
||||
|
||||
@@ -35,7 +35,7 @@ class ApplicationManager {
|
||||
log('ApplicationManager::getUserAgent: $userAgent');
|
||||
return userAgent;
|
||||
} catch(e) {
|
||||
logError('ApplicationManager::getUserAgent: Exception: $e');
|
||||
logWarning('ApplicationManager::getUserAgent: Exception: $e');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class FileUtils {
|
||||
log('FileUtils::getFolder(): $folderPath');
|
||||
return Directory(folderPath);
|
||||
} catch (e) {
|
||||
logError('FileUtils::getFolder():EXCEPTION: $e');
|
||||
logWarning('FileUtils::getFolder():EXCEPTION: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ class FileUtils {
|
||||
log('FileUtils::removeFolder: Remove ${dir.path} success');
|
||||
}
|
||||
} catch (e) {
|
||||
logError('FileUtils::removeFolder():EXCEPTION: $e');
|
||||
logWarning('FileUtils::removeFolder():EXCEPTION: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ class FileUtils {
|
||||
await file.delete();
|
||||
}
|
||||
} catch (e) {
|
||||
logError('$runtimeType::deleteCompressedFileOnMobile: error: $e');
|
||||
logWarning('$runtimeType::deleteCompressedFileOnMobile: error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class FileUtils {
|
||||
log('FileUtils::getCharsetFromBytes: FILE_CHARSET = ${decodedResult.charset}');
|
||||
return decodedResult.charset;
|
||||
} catch (e) {
|
||||
logError('FileUtils::getCharsetFromBytes: Exception: $e');
|
||||
logWarning('FileUtils::getCharsetFromBytes: Exception: $e');
|
||||
return DEFAULT_CHARSET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ class HtmlUtils {
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
logError('AppUtils::openNewWindowByUrl:Exception = $e');
|
||||
logWarning('AppUtils::openNewWindowByUrl:Exception = $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -683,7 +683,7 @@ class HtmlUtils {
|
||||
titleElements.first.text = title;
|
||||
}
|
||||
} catch (e) {
|
||||
logError('AppUtils::setWindowBrowserTitle:Exception = $e');
|
||||
logWarning('AppUtils::setWindowBrowserTitle:Exception = $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,7 +691,7 @@ class HtmlUtils {
|
||||
try {
|
||||
return htmlUnescape.convert(input);
|
||||
} catch (e) {
|
||||
logError('HtmlUtils::unescapeHtml:Exception = $e');
|
||||
logWarning('HtmlUtils::unescapeHtml:Exception = $e');
|
||||
return input;
|
||||
}
|
||||
}
|
||||
@@ -718,7 +718,7 @@ class HtmlUtils {
|
||||
log('HtmlUtils::isOldSafari:Version = $version');
|
||||
return version != null && version < 17;
|
||||
} catch (e) {
|
||||
logError('HtmlUtils::isOldSafari:Exception = $e');
|
||||
logWarning('HtmlUtils::isOldSafari:Exception = $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -893,7 +893,7 @@ class HtmlUtils {
|
||||
|
||||
return container.innerHtml;
|
||||
} catch (e) {
|
||||
logError('HtmlUtils::wrapPlainTextLinks:Exception = $e');
|
||||
logWarning('HtmlUtils::wrapPlainTextLinks:Exception = $e');
|
||||
return htmlString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class Domain with EquatableMixin {
|
||||
InternetAddress(value);
|
||||
return true;
|
||||
} catch (e) {
|
||||
logError('Domain::validIPAddress: Exception = $e');
|
||||
logWarning('Domain::validIPAddress: Exception = $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class MailAddress with EquatableMixin {
|
||||
throw AddressException('No domain found at position ${pos + 1} in "$address"');
|
||||
}
|
||||
} catch (e) {
|
||||
logError('MailAddress::validate: Exception = $e');
|
||||
logWarning('MailAddress::validate: Exception = $e');
|
||||
if (e is AddressException) {
|
||||
rethrow;
|
||||
} else {
|
||||
|
||||
@@ -65,7 +65,7 @@ class PreviewEmlFileUtils {
|
||||
${listAttachment?.isNotEmpty == true ? _createAttachmentsElement(listAttachment: listAttachment ?? [], titleAttachment: titleAttachment) : ''}
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PreviewEmlFileUtils::_createEmailElement: Exception = $e');
|
||||
logWarning('PreviewEmlFileUtils::_createEmailElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class PreviewEmlFileUtils {
|
||||
</div>
|
||||
''';
|
||||
} catch (e) {
|
||||
logError('PreviewEmlFileUtils::_createRecipientHtmlTag: Exception = $e');
|
||||
logWarning('PreviewEmlFileUtils::_createRecipientHtmlTag: Exception = $e');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ class PreviewEmlFileUtils {
|
||||
</div>
|
||||
''';
|
||||
} catch (e) {
|
||||
logError('PreviewEmlFileUtils::_createAttachmentsElement: Exception = $e');
|
||||
logWarning('PreviewEmlFileUtils::_createAttachmentsElement: Exception = $e');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class PrintUtils {
|
||||
</table>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createUserInformationElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createUserInformationElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class PrintUtils {
|
||||
try {
|
||||
return Element.html('<hr />');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::dividerElement: Exception = $e');
|
||||
logWarning('PrintUtils::dividerElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class PrintUtils {
|
||||
</table>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createSubjectElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createSubjectElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class PrintUtils {
|
||||
</table>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createSenderElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createSenderElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class PrintUtils {
|
||||
element.text = '$prefix: $emailAddress';
|
||||
return element.outerHtml;
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createRecipientHtmlTag: Exception = $e');
|
||||
logWarning('PrintUtils::_createRecipientHtmlTag: Exception = $e');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class PrintUtils {
|
||||
</tr>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createRecipientsElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createRecipientsElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class PrintUtils {
|
||||
</tr>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createEmailContentElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createEmailContentElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ class PrintUtils {
|
||||
</table>
|
||||
''');
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createAttachmentsElement: Exception = $e');
|
||||
logWarning('PrintUtils::_createAttachmentsElement: Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class StringConvert {
|
||||
try {
|
||||
return utf8.decode(base64Decode(text));
|
||||
} catch (e) {
|
||||
logError('StringConvert::decodeBase64ToString:Exception = $e');
|
||||
logWarning('StringConvert::decodeBase64ToString:Exception = $e');
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class StringConvert {
|
||||
log('StringConvert::getMediaTypeFromBase64ImageTag:mimeType = $mimeType');
|
||||
return MediaType.parse(mimeType);
|
||||
} catch (e) {
|
||||
logError('StringConvert::getMimeTypeFromBase64ImageTag:Exception = $e');
|
||||
logWarning('StringConvert::getMimeTypeFromBase64ImageTag:Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class StringConvert {
|
||||
final contentOriginal = emailDocument.body?.innerHtml ?? content;
|
||||
return contentOriginal;
|
||||
} catch (e) {
|
||||
logError('StringConvert::getContentOriginal:Exception = $e');
|
||||
logWarning('StringConvert::getContentOriginal:Exception = $e');
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class WebLinkGenerator {
|
||||
searchParams: searchParams,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('[WebLinkGenerator] Error: $e');
|
||||
logWarning('[WebLinkGenerator] Error: $e');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user