Skip to content

Commit

Permalink
Clean up log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jun 18, 2024
1 parent 045277c commit ff786b6
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 44 deletions.
5 changes: 2 additions & 3 deletions core/lib/utils/app_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ Future<void> log(String? value, {Level level = Level.info}) async {
}
}

final message = '[TwakeMail] $logsStr';
// ignore: avoid_print
print(message);
print('[TwakeMail] $logsStr');

if (LogTracking().enableTraceLog) {
await LogTracking().addLog(message: message);
await LogTracking().addLog(message: logsStr);
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/lib/utils/html/html_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class HtmlUtils {

static const unregisterDropListener = (
script: '''
console.log("unregisterDropListener");
const editor = document.querySelector(".note-editable");
const newEditor = editor.cloneNode(true);
editor.parentNode.replaceChild(newEditor, editor);''',
Expand Down Expand Up @@ -76,12 +75,12 @@ class HtmlUtils {
required String base64Data,
required String mimeType
}) {
log('HtmlUtils::convertBase64ToImageResourceData:');
mimeType = validateHtmlImageResourceMimeType(mimeType);
if (!base64Data.endsWith('==')) {
base64Data.append('==');
}
final imageResource = 'data:$mimeType;base64,$base64Data';
log('HtmlUtils::convertBase64ToImageResourceData:imageResource: $imageResource');
return imageResource;
}

Expand Down
39 changes: 19 additions & 20 deletions lib/features/base/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ abstract class BaseController extends GetxController
return null;
}

void handleErrorViewState(Object error, StackTrace stackTrace) {}
void handleErrorViewState(Object error, StackTrace stackTrace) {
logError('BaseController::handleErrorViewState: $error | $stackTrace');
}

void handleExceptionAction({Failure? failure, Exception? exception}) {
logError('BaseController::handleExceptionAction():failure: $failure | exception: $exception');
Expand All @@ -167,15 +169,17 @@ abstract class BaseController extends GetxController
}

if (!authorizationInterceptors.isAppRunning) {
logError('BaseController::handleExceptionAction:isAppRunning = false');
return;
}
if (exception is BadCredentialsException || exception is ConnectionError) {
logError('BaseController::handleExceptionAction: exception is BadCredentialsException or ConnectionError');
clearDataAndGoToLoginPage();
}
}

void handleFailureViewState(Failure failure) async {
logError('BaseController::handleFailureViewState(): ${failure.runtimeType}');
logError('BaseController::handleFailureViewState(): $failure');
if (failure is LogoutOidcFailure) {
if (_isFcmEnabled) {
_getStoredFirebaseRegistrationFromCache();
Expand All @@ -189,7 +193,7 @@ abstract class BaseController extends GetxController
}

void handleSuccessViewState(Success success) async {
log('BaseController::handleSuccessViewState(): ${success.runtimeType}');
log('BaseController::handleSuccessViewState(): $success');
if (success is LogoutOidcSuccess) {
if (_isFcmEnabled) {
_getStoredFirebaseRegistrationFromCache();
Expand All @@ -203,24 +207,8 @@ abstract class BaseController extends GetxController
}
}

void startFpsMeter() {
FpsManager().start();
fpsCallback = (fpsInfo) {
log('BaseController::startFpsMeter(): $fpsInfo');
};
if (fpsCallback != null) {
FpsManager().addFpsCallback(fpsCallback!);
}
}

void stopFpsMeter() {
FpsManager().stop();
if (fpsCallback != null) {
FpsManager().removeFpsCallback(fpsCallback!);
}
}

void injectAutoCompleteBindings(Session? session, AccountId? accountId) {
log('BaseController::injectAutoCompleteBindings:');
try {
ContactAutoCompleteBindings().dependencies();
requireCapability(session!, accountId!, [tmailContactCapabilityIdentifier]);
Expand All @@ -231,6 +219,7 @@ abstract class BaseController extends GetxController
}

void injectMdnBindings(Session? session, AccountId? accountId) {
log('BaseController::injectMdnBindings:');
try {
requireCapability(session!, accountId!, [CapabilityIdentifier.jmapMdn]);
MdnInteractorBindings().dependencies();
Expand All @@ -240,6 +229,7 @@ abstract class BaseController extends GetxController
}

void injectForwardBindings(Session? session, AccountId? accountId) {
log('BaseController::injectForwardBindings:');
try {
requireCapability(session!, accountId!, [capabilityForward]);
ForwardingInteractorsBindings().dependencies();
Expand All @@ -249,6 +239,7 @@ abstract class BaseController extends GetxController
}

void injectRuleFilterBindings(Session? session, AccountId? accountId) {
log('BaseController::injectRuleFilterBindings:');
try {
requireCapability(session!, accountId!, [capabilityRuleFilter]);
EmailRulesInteractorBindings().dependencies();
Expand All @@ -258,6 +249,7 @@ abstract class BaseController extends GetxController
}

Future<void> injectFCMBindings(Session? session, AccountId? accountId) async {
log('BaseController::injectFCMBindings:');
try {
requireCapability(session!, accountId!, [FirebaseCapability.fcmIdentifier]);
log('BaseController::injectFCMBindings: fcmAvailable = ${AppConfig.fcmAvailable}');
Expand Down Expand Up @@ -289,6 +281,7 @@ abstract class BaseController extends GetxController
FirebaseCapability.fcmIdentifier.isSupported(session, accountId) && AppConfig.fcmAvailable;

void goToLogin() {
log('BaseController::goToLogin:currentRoute = ${Get.currentRoute}');
if (Get.currentRoute != AppRoutes.login) {
pushAndPopAll(
AppRoutes.login,
Expand All @@ -300,6 +293,7 @@ abstract class BaseController extends GetxController
}

void logout(Session? session, AccountId? accountId) async {
log('BaseController::logout:accountId = $accountId');
if (session == null || accountId == null) {
await clearDataAndGoToLoginPage();
return;
Expand All @@ -317,6 +311,7 @@ abstract class BaseController extends GetxController
}

void _destroyFirebaseRegistration(FirebaseRegistrationId firebaseRegistrationId) async {
log('BaseController::_destroyFirebaseRegistration:firebaseRegistrationId = $firebaseRegistrationId');
_destroyFirebaseRegistrationInteractor = getBinding<DestroyFirebaseRegistrationInteractor>();
if (_destroyFirebaseRegistrationInteractor != null) {
consumeState(_destroyFirebaseRegistrationInteractor!.execute(firebaseRegistrationId));
Expand All @@ -326,6 +321,7 @@ abstract class BaseController extends GetxController
}

void _getStoredFirebaseRegistrationFromCache() async {
log('BaseController::_getStoredFirebaseRegistrationFromCache:');
_getStoredFirebaseRegistrationInteractor = getBinding<GetStoredFirebaseRegistrationInteractor>();
if (_getStoredFirebaseRegistrationInteractor != null) {
consumeState(_getStoredFirebaseRegistrationInteractor!.execute());
Expand All @@ -341,6 +337,7 @@ abstract class BaseController extends GetxController
}

Future<void> clearAllData() async {
log('BaseController::clearAllData:');
if (isAuthenticatedWithOidc) {
await _clearOidcAuthData();
} else {
Expand All @@ -349,6 +346,7 @@ abstract class BaseController extends GetxController
}

Future<void> _clearBasicAuthData() async {
log('BaseController::_clearBasicAuthData:');
await Future.wait([
deleteCredentialInteractor.execute(),
cachingManager.clearAll(),
Expand All @@ -363,6 +361,7 @@ abstract class BaseController extends GetxController
}

Future<void> _clearOidcAuthData() async {
log('BaseController::_clearOidcAuthData:');
await Future.wait([
deleteAuthorityOidcInteractor.execute(),
cachingManager.clearAll(),
Expand Down
13 changes: 12 additions & 1 deletion lib/features/base/reloadable/reloadable_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ abstract class ReloadableController extends BaseController {

@override
void handleFailureViewState(Failure failure) {
logError('ReloadableController::handleFailureViewState(): failure: $failure');
if (failure is GetCredentialFailure ||
failure is GetStoredTokenOidcFailure ||
failure is GetAuthenticatedAccountFailure) {
log('ReloadableController::handleFailureViewState(): failure: $failure');
goToLogin();
} else if (failure is GetSessionFailure) {
_handleGetSessionFailure(failure.exception);
Expand All @@ -44,6 +44,7 @@ abstract class ReloadableController extends BaseController {

@override
void handleSuccessViewState(Success success) {
log('ReloadableController::handleSuccessViewState:');
if (success is GetCredentialViewState) {
_handleGetCredentialSuccess(success);
} else if (success is GetSessionSuccess) {
Expand All @@ -59,14 +60,17 @@ abstract class ReloadableController extends BaseController {
* trigger reload by getting Credential again then setting up Interceptor and retrieving session
* */
void reload() {
log('ReloadableController::reload:');
getAuthenticatedAccountAction();
}

void getAuthenticatedAccountAction() {
log('ReloadableController::getAuthenticatedAccountAction:');
consumeState(_getAuthenticatedAccountInteractor.execute());
}

void _setUpInterceptors(GetCredentialViewState credentialViewState) {
log('ReloadableController::_setUpInterceptors:');
dynamicUrlInterceptors.setJmapUrl(credentialViewState.baseUrl.origin);
dynamicUrlInterceptors.changeBaseUrl(credentialViewState.baseUrl.origin);
authorizationInterceptors.setBasicAuthorization(
Expand All @@ -80,15 +84,18 @@ abstract class ReloadableController extends BaseController {
}

void _handleGetCredentialSuccess(GetCredentialViewState credentialViewState) {
log('ReloadableController::_handleGetCredentialSuccess:');
_setUpInterceptors(credentialViewState);
getSessionAction();
}

void getSessionAction() {
log('ReloadableController::getSessionAction:');
consumeState(_getSessionInteractor.execute());
}

void _handleGetSessionFailure(dynamic exception) {
logError('ReloadableController::_handleGetSessionFailure:exception = $exception');
if (currentContext != null && currentOverlayContext != null && exception !is BadCredentialsException) {
appToast.showToastErrorMessage(
currentOverlayContext!,
Expand All @@ -99,6 +106,7 @@ abstract class ReloadableController extends BaseController {
}

void _handleGetSessionSuccess(GetSessionSuccess success) {
log('ReloadableController::_handleGetSessionSuccess:');
final session = success.session;
final personalAccount = session.personalAccount;
final apiUrl = session.getQualifiedApiUrl(baseUrl: dynamicUrlInterceptors.jmapUrl);
Expand All @@ -114,11 +122,13 @@ abstract class ReloadableController extends BaseController {
void handleReloaded(Session session) {}

void _handleGetStoredTokenOIDCSuccess(GetStoredTokenOidcSuccess tokenOidcSuccess) {
log('ReloadableController::_handleGetStoredTokenOIDCSuccess:');
_setUpInterceptorsOidc(tokenOidcSuccess);
getSessionAction();
}

void _setUpInterceptorsOidc(GetStoredTokenOidcSuccess tokenOidcSuccess) {
log('ReloadableController::_setUpInterceptorsOidc:');
dynamicUrlInterceptors.setJmapUrl(tokenOidcSuccess.baseUrl.toString());
dynamicUrlInterceptors.changeBaseUrl(tokenOidcSuccess.baseUrl.toString());
authorizationInterceptors.setTokenAndAuthorityOidc(
Expand All @@ -139,6 +149,7 @@ abstract class ReloadableController extends BaseController {
}

void updateAuthenticationAccount(Session session, AccountId accountId, UserName userName) {
log('ReloadableController::updateAuthenticationAccount:');
final apiUrl = session.getQualifiedApiUrl(baseUrl: dynamicUrlInterceptors.jmapUrl);
if (apiUrl.isNotEmpty) {
consumeState(_updateAuthenticationAccountInteractor.execute(accountId, apiUrl, userName));
Expand Down
8 changes: 8 additions & 0 deletions lib/features/caching/caching_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CachingManager {
);

Future<void> clearAll() async {
log('CachingManager::clearAll:');
await Future.wait([
_stateCacheClient.clearAllData(),
_mailboxCacheClient.clearAllData(),
Expand All @@ -85,6 +86,7 @@ class CachingManager {
}

Future<void> clearData() async {
log('CachingManager::clearData:');
await Future.wait([
_stateCacheClient.clearAllData(),
_mailboxCacheClient.clearAllData(),
Expand All @@ -103,13 +105,15 @@ class CachingManager {
}

Future<void> clearEmailCacheAndStateCacheByTupleKey(AccountId accountId, Session session) {
log('CachingManager::clearEmailCacheAndStateCacheByTupleKey:');
return Future.wait([
_stateCacheClient.deleteItem(StateType.email.getTupleKeyStored(accountId, session.username)),
_emailCacheClient.clearAllData(),
], eagerError: true);
}

Future<void> clearEmailCacheAndAllStateCache() {
log('CachingManager::clearEmailCacheAndAllStateCache:');
return Future.wait([
_stateCacheClient.clearAllData(),
_emailCacheClient.clearAllData(),
Expand All @@ -122,21 +126,25 @@ class CachingManager {
}

Future<int?> getLatestVersion() {
log('CachingManager::getLatestVersion:');
return _hiveCacheVersionClient.getLatestVersion();
}

Future<void> closeHive() async {
log('CachingManager::closeHive:');
return await HiveCacheConfig.instance.closeHive();
}

Future<void> clearAllFileInStorage() async {
log('CachingManager::clearAllFileInStorage:');
await Future.wait([
_fileUtils.removeFolder(CachingConstants.newEmailsContentFolderName),
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName),
]);
}

Future<void> clearLoginRecentData() async {
log('CachingManager::clearLoginRecentData:');
await Future.wait([
_recentLoginUrlCacheClient.clearAllData(),
_recentLoginUsernameCacheClient.clearAllData(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,6 @@ class ComposerController extends BaseController with DragDropFileMixin {
}) async {
final newEmailBody = await _getContentInEditor();
final oldEmailBody = _initTextEditor ?? '';
log('ComposerController::_validateEmailChange: newEmailBody = $newEmailBody | oldEmailBody = $oldEmailBody');
final isEmailBodyChanged = !oldEmailBody.trim().isSame(newEmailBody.trim());

final newEmailSubject = subjectEmail.value ?? '';
Expand Down
4 changes: 1 addition & 3 deletions lib/features/email/data/local/html_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ class HtmlAnalyzer {
}

Future<String> removeCollapsedExpandedSignatureEffect({required String emailContent}) async {
log('HtmlAnalyzer::removeCollapsedExpandedSignatureEffect: BEFORE = $emailContent');
log('HtmlAnalyzer::removeCollapsedExpandedSignatureEffect');
final document = parse(emailContent);
final signatureElements = document.querySelectorAll('div.tmail-signature');
await Future.wait(signatureElements.map((signatureTag) async {
final signatureChildren = signatureTag.children;
for (var child in signatureChildren) {
log('HtmlAnalyzer::removeCollapsedExpandedSignatureEffect: CHILD = ${child.outerHtml}');
if (child.attributes['class']?.contains('tmail-signature-button') == true) {
child.remove();
} else if (child.attributes['class']?.contains('tmail-signature-content') == true) {
Expand All @@ -154,7 +153,6 @@ class HtmlAnalyzer {
}
}));
final newContent = document.body?.innerHtml ?? emailContent;
log('HtmlAnalyzer::removeCollapsedExpandedSignatureEffect: AFTER = $newContent');
return newContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ extension ListAccountCacheExtension on List<AccountCache> {
List<AccountCache> unselected() => map((account) => account.unselected()).toList();

List<AccountCache> removeDuplicated() {
log('ListAccountCacheExtension::removeDuplicated:BEFORE: $this');
final listAccountId = map((account) => account.accountId).whereNotNull().toSet();
log('ListAccountCacheExtension::removeDuplicated:listAccountId: $listAccountId');
retainWhere((account) => listAccountId.remove(account.accountId));
log('ListAccountCacheExtension::removeDuplicated:listAccount: $this');
log('ListAccountCacheExtension::removeDuplicated:AFTER: $this');
return this;
}

Expand Down
1 change: 1 addition & 0 deletions lib/features/login/data/local/account_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AccountCacheManager {
.removeDuplicated()
.whereNot((account) => account.accountId == newAccountCache.accountId)
.toList();
log('AccountCacheManager::setCurrentAccount:newAllAccounts = $newAllAccounts');
if (newAllAccounts.isNotEmpty) {
await _accountCacheClient.clearAllData();
await _accountCacheClient.updateMultipleItem(newAllAccounts.toMap());
Expand Down
Loading

0 comments on commit ff786b6

Please sign in to comment.