Skip to content

Commit

Permalink
rearrange details in log message to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenMassaro committed Nov 14, 2023
1 parent d0952b0 commit 1cdf4b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/email/job/SyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public synchronized void startSync(String bitwardenMasterPassword) throws Except

List<Future<SyncStatusResult>> syncFutures = new ArrayList<>();
for (UUID accountBitwardenId : accounts) {
log.debug("Submitting task for account {}", accountBitwardenId);
log.debug("{} - Submitting sync task", accountBitwardenId);
syncFutures.add(syncService.sync(accountBitwardenId, bitwardenMasterPassword));
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/email/service/ImapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class ImapService {
public void onRemoval(RemovalNotification<String, Store> notification) {
try {
if (notification.getValue() != null) {
log.debug("Closing store for {}", notification.getKey());
log.debug("{} - Closing store", notification.getKey());
notification.getValue().close();
}
} catch (MessagingException e) {
log.warn("Failed to close expired store for {}", notification.getKey(), e);
log.warn("{} - Failed to close expired store", notification.getKey(), e);
}
}
})
Expand Down Expand Up @@ -67,15 +67,15 @@ public List<Message> getInboxMessages(String hostname, int port, String username
}
}

log.debug("Processing email {} of {} for {}", finalI + 1, messages.length, username);
log.debug("{} - Processing email {} of {}", username, finalI + 1, messages.length);
returnMessages.add(new Message(message, uid, messageAlreadyDownloaded, username, accountBitwardenId));
return null; // this is useless, but is here to make this a callable, so that we can throw exceptions
});

try {
messageProcessingFuture.get(60, TimeUnit.SECONDS);
} catch (TimeoutException e) {
log.warn("Ran out of time while processing message {} of {} for {}", finalI + 1, messages.length, username, e);
log.warn("{} - Ran out of time while processing message {} of {}", username, finalI + 1, messages.length, e);
messageProcessingFuture.cancel(true);
allSuccess = false;
}
Expand All @@ -90,7 +90,7 @@ public List<Message> getInboxMessages(String hostname, int port, String username

@Async
public void setReadIndicator(long id, boolean readInd) throws Exception {
log.debug("Marking email {} as read ind {}", id, readInd);
log.debug("{} - Marking email as read ind {}", id, readInd);
Message message = messageService.get(id);
Store store = getStore(message);

Expand Down Expand Up @@ -130,7 +130,7 @@ private Store getStore(Item item) throws Exception {
}

private Store getStore(String hostname, int port, String username, String decryptedPassword, boolean isRetry) throws Exception {
log.debug("Getting store for {} {}", hostname, username);
log.debug("{} - Getting store for {}", username, hostname);
Store cached = storeCache.get(username, () -> {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Expand All @@ -151,7 +151,7 @@ private Store getStore(String hostname, int port, String username, String decryp
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect(hostname, port, username, decryptedPassword);
log.debug("Connected to store for {} {}", hostname, username);
log.debug("{} - Connected to store for {}", username, hostname);
return store;
});
if (cached.isConnected()) {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/email/service/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Future<SyncStatusResult> sync(UUID account, String bitwardenMasterPasswor

try {
Item item = bitwardenService.getLogin(account, bitwardenMasterPassword);
log.debug("Sync started for {}", item.getLogin().getUsername());
log.debug("{} - Sync started", item.getLogin().getUsername());
username = item.getLogin().getUsername();
List<Message> dbMessages = messageService.list(account);
List<Message> imapMessages;
Expand All @@ -59,8 +59,8 @@ public Future<SyncStatusResult> sync(UUID account, String bitwardenMasterPasswor
deletedCount++;
}
}
log.debug("Deleted {} messages from local database while processing account {}.",
deletedCount, item.getLogin().getUsername());
log.debug("{} - Deleted {} messages from local database.",
item.getLogin().getUsername(), deletedCount);

// then add all messages that do exist on the imap server
long insertedCount = 0;
Expand All @@ -74,26 +74,26 @@ public Future<SyncStatusResult> sync(UUID account, String bitwardenMasterPasswor
insertedCount++;
} catch (Exception e) {
messageFailure = true;
log.error("Failed to insert new message with UID {} while processing account {}.", imapMessage.getUid(), item.getLogin().getUsername(), e);
log.error("{} - Failed to insert new message with UID {}.", item.getLogin().getUsername(), imapMessage.getUid(), e);
}
} else {
// if the message has a different read indicator in the database than IMAP
if (imapMessage.isReadInd() != match.isReadInd()) {
messageService.setReadIndicator(match.getId(), imapMessage.isReadInd());
log.debug("Changed read indicator for email ID {} to {}.",
log.debug("{} - Changed read indicator to {}.",
match.getId(), imapMessage.isReadInd() ? "read" : "unread");
changedReadIndCount++;
}
}
}
log.debug("Inserted {} messages into local database while processing account {}.", insertedCount, item.getLogin().getUsername());
log.debug("Changed read indicator for {} messages while processing account {}.", changedReadIndCount, item.getLogin().getUsername());
log.debug("{} - Inserted {} messages into local database.", item.getLogin().getUsername(), insertedCount);
log.debug("{} - Changed read indicator for {} messages.", item.getLogin().getUsername(), changedReadIndCount);
totalChangedReadIndCount += changedReadIndCount;
totalDeletedCount += deletedCount;
totalInsertedCount += insertedCount;
} catch (Exception e) {
accountFailure = true;
log.error("Exception while processing account {} {}.", account, username, e);
log.error("{} - Exception while processing account {}.", username, account, e);
}

ExecStatusEnum result;
Expand All @@ -104,7 +104,7 @@ public Future<SyncStatusResult> sync(UUID account, String bitwardenMasterPasswor
} else {
result = ExecStatusEnum.RULE_END_ACCOUNT_FAILURE;
}
log.debug("Sync finished for {} {}", account, username);
log.debug("{} - Sync finished for {}", username, account);
return new AsyncResult<>(new SyncStatusResult(totalInsertedCount, totalDeletedCount, totalChangedReadIndCount, result, username));
}
}

0 comments on commit 1cdf4b3

Please sign in to comment.