TF-4136 refactor(logging): replace logError with logWarning for non-critical cases

This commit is contained in:
dab246
2026-01-02 12:18:38 +07:00
committed by Dat H. Pham
parent 73dcb6067c
commit a23d15a9ca
160 changed files with 382 additions and 360 deletions
@@ -143,7 +143,7 @@ class DownloadManager {
);
}
} catch (exception) {
logError('DownloadManager::openDownloadedFileWeb(): ERROR: $exception');
logWarning('DownloadManager::openDownloadedFileWeb(): ERROR: $exception');
rethrow;
}
}
@@ -153,7 +153,7 @@ class DownloadManager {
final contentType = responseBody.headers[Headers.contentTypeHeader];
return MediaType.parse(contentType!.first);
} catch (e) {
logError('DownloadManager::_extractMediaTypeFromResponse(): $e');
logWarning('DownloadManager::_extractMediaTypeFromResponse(): $e');
return null;
}
}
@@ -37,7 +37,7 @@ extension StringExtension on String {
}
}
} catch (e) {
logError('StringExtension::firstLetterToUpperCase(): $e');
logWarning('StringExtension::firstLetterToUpperCase(): $e');
return '';
}
}
@@ -94,7 +94,7 @@ extension StringExtension on String {
return 0;
}
} catch (e) {
logError('StringExtension::_generateGradientColorIndex(): $e');
logWarning('StringExtension::_generateGradientColorIndex(): $e');
return 0;
}
}
@@ -26,7 +26,7 @@ extension URIExtension on Uri {
try {
return origin.isNotEmpty;
} catch (e) {
logError('URIExtension::hasOrigin:Exception = $e');
logWarning('URIExtension::hasOrigin:Exception = $e');
return false;
}
}
@@ -46,7 +46,7 @@ abstract class DomTransformer {
return null;
}
} catch (e) {
logError('DomTransformer::findImageUrlFromStyleTag:Exception: $e');
logWarning('DomTransformer::findImageUrlFromStyleTag:Exception: $e');
return null;
}
}
@@ -28,7 +28,7 @@ class AddLazyLoadingForBackgroundImageTransformer extends DomTransformer {
}
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -36,7 +36,7 @@ class BlockCodeTransformer extends DomTransformer {
''';
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -29,7 +29,7 @@ class BlockQuotedTransformer extends DomTransformer {
''';
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -27,7 +27,7 @@ class HideDraftSignatureTransformer extends DomTransformer {
signature.attributes['style'] = '$currentStyle; display: none;';
}
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -52,7 +52,7 @@ class ImageTransformer extends DomTransformer {
}
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
@@ -48,7 +48,7 @@ class NormalizeLineHeightInStyleTransformer extends DomTransformer {
}
}
} catch (e) {
logError('$runtimeType::process: Exception = $e');
logWarning('$runtimeType::process: Exception = $e');
}
}
}
@@ -23,7 +23,7 @@ class RemoveCollapsedSignatureButtonTransformer extends DomTransformer {
element.remove();
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -31,7 +31,7 @@ class RemoveLazyLoadingForBackgroundImageTransformer extends DomTransformer {
element.attributes.remove('lazy');
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -21,7 +21,7 @@ class RemoveLazyLoadingImageTransformer extends DomTransformer {
element.attributes.remove('loading');
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -26,7 +26,7 @@ class RemoveMaxWidthInImageStyleTransformer extends DomTransformer {
}
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -22,7 +22,7 @@ class RemoveStyleTagOutsideTransformer extends DomTransformer {
element.remove();
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -26,7 +26,7 @@ class SanitizeHyperLinkTagInHtmlTransformer extends DomTransformer {
_addNoReferrerForRelProperty(element);
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
@@ -23,7 +23,7 @@ class RemoveScriptTransformer extends DomTransformer {
scriptElement.remove();
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -23,7 +23,7 @@ class SignatureTransformer extends DomTransformer {
element.attributes['class'] = 'tmail-signature-blocked';
}));
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
}
}
}
@@ -56,7 +56,7 @@ class SanitizeAutolinkFilter {
log('SanitizeAutolinkFilter::process:htmlTextBuffer = $textSanitized');
return textSanitized;
} catch (e) {
logError('$runtimeType::process:Exception = $e');
logWarning('$runtimeType::process:Exception = $e');
return inputText;
}
}
@@ -24,7 +24,7 @@ class SanitizeUrl {
}
return originalUrl;
} catch (e) {
logError('SanitizeUrl::process:Exception = $e');
logWarning('SanitizeUrl::process:Exception = $e');
return inputText;
}
}
@@ -166,7 +166,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
_handleHyperLinkEvent(data['url']);
}
} catch (e) {
logError('$runtimeType::_handleMessageEvent:Exception = $e');
logWarning('$runtimeType::_handleMessageEvent:Exception = $e');
}
}
@@ -212,7 +212,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
}
}
} catch (e) {
logError('$runtimeType::_handleIframeOnScrollChangedListener:Exception = $e');
logWarning('$runtimeType::_handleIframeOnScrollChangedListener:Exception = $e');
}
}
@@ -309,7 +309,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
log('$runtimeType::_handleOnIFrameKeyboardEvent:📥 Shortcut pressed: $shortcut');
widget.onIFrameKeyboardShortcutAction?.call(shortcut);
} catch (e) {
logError('$runtimeType::_handleOnIFrameKeyboardEvent: Exception = $e');
logWarning('$runtimeType::_handleOnIFrameKeyboardEvent: Exception = $e');
}
}
@@ -323,7 +323,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
log('$runtimeType::_handleOnIFrameClickEvent: $data');
widget.onIFrameClickAction?.call();
} catch (e) {
logError('$runtimeType::_handleOnIFrameClickEvent: Exception = $e');
logWarning('$runtimeType::_handleOnIFrameClickEvent: Exception = $e');
}
}
@@ -354,7 +354,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
}
}
} catch (e) {
logError('$runtimeType::_handleOnIFrameLinkHoverEvent: Exception = $e');
logWarning('$runtimeType::_handleOnIFrameLinkHoverEvent: Exception = $e');
}
}
@@ -363,7 +363,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb>
log('$runtimeType::_handleOnIFrameLinkOutEvent: $data');
_tooltipOverlay?.hide();
} catch (e) {
logError('$runtimeType::_handleOnIFrameLinkOutEvent: Exception = $e');
logWarning('$runtimeType::_handleOnIFrameLinkOutEvent: Exception = $e');
}
}
@@ -411,7 +411,7 @@ class HtmlContentViewState extends State<HtmlContentViewer> with AutomaticKeepAl
try {
_webViewController.dispose();
} catch (e) {
logError('_HtmlContentViewState:dispose:_webViewController.dispose: $e');
logWarning('_HtmlContentViewState:dispose:_webViewController.dispose: $e');
}
} else {
_webViewController.dispose();
@@ -111,7 +111,7 @@ class QuickSearchSuggestionListState<T, P, R>
try {
return await widget.fetchRecentActionCallback?.call(queryString);
} catch (e) {
logError('SuggestionsListState::_getRecent:Exception = $e');
logWarning('SuggestionsListState::_getRecent:Exception = $e');
return null;
}
}
@@ -120,7 +120,7 @@ class QuickSearchSuggestionListState<T, P, R>
try {
return await widget.contactSuggestionCallback?.call(queryString);
} catch (e) {
logError('SuggestionsListState::_getListContact:Exception = $e');
logWarning('SuggestionsListState::_getListContact:Exception = $e');
return null;
}
}
@@ -129,7 +129,7 @@ class QuickSearchSuggestionListState<T, P, R>
try {
return await widget.suggestionsCallback?.call(queryString);
} catch (e) {
logError('SuggestionsListState::_getListSuggestion:Exception = $e');
logWarning('SuggestionsListState::_getListSuggestion:Exception = $e');
return null;
}
}
+22 -21
View File
@@ -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
+1 -1
View File
@@ -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 '';
}
}
+4 -4
View File
@@ -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;
}
}
+5 -5
View File
@@ -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;
}
}
+1 -1
View File
@@ -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;
}
}
+1 -1
View File
@@ -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 {
+3 -3
View File
@@ -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 '';
}
}
+8 -8
View File
@@ -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;
}
}
+3 -3
View File
@@ -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;
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ class WebLinkGenerator {
searchParams: searchParams,
);
} catch (e) {
logError('[WebLinkGenerator] Error: $e');
logWarning('[WebLinkGenerator] Error: $e');
return '';
}
}