diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-09-23 18:00:00 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-09-23 21:48:55 +0300 |
commit | 635e03fc71980d4b6f7b4aa2958af7a557c7f974 (patch) | |
tree | 53ba2e799afe223dbaca5e5aa1377294176626d5 /lib/IMAP | |
parent | 57e02700a69edccddeaa1f169cb18335e8baf5db (diff) |
Add debug output to sync processes triggered via the CLI
Just like a CLI priority inbox model training gives all the details, we
want to have the same to diagnose slow/faulty account syncs. This
changes the console logger adapter for the PSR logger and adds it to the
sync process.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/IMAP')
-rw-r--r-- | lib/IMAP/MailboxSync.php | 17 | ||||
-rw-r--r-- | lib/IMAP/Threading/ThreadBuilder.php | 8 |
2 files changed, 13 insertions, 12 deletions
diff --git a/lib/IMAP/MailboxSync.php b/lib/IMAP/MailboxSync.php index baeadae88..563cbfe50 100644 --- a/lib/IMAP/MailboxSync.php +++ b/lib/IMAP/MailboxSync.php @@ -30,6 +30,7 @@ use Horde_Imap_Client_Data_Namespace; use Horde_Imap_Client_Exception; use Horde_Imap_Client_Namespace_List; use OCA\Mail\Exception\ServiceException; +use Psr\Log\LoggerInterface; use function in_array; use function json_encode; use OCA\Mail\Account; @@ -38,7 +39,6 @@ use OCA\Mail\Db\Mailbox; use OCA\Mail\Db\MailboxMapper; use OCA\Mail\Folder; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\ILogger; class MailboxSync { @@ -57,29 +57,26 @@ class MailboxSync { /** @var ITimeFactory */ private $timeFactory; - /** @var ILogger */ - private $logger; - public function __construct(MailboxMapper $mailboxMapper, FolderMapper $folderMapper, MailAccountMapper $mailAccountMapper, IMAPClientFactory $imapClientFactory, - ITimeFactory $timeFactory, - ILogger $logger) { + ITimeFactory $timeFactory) { $this->mailboxMapper = $mailboxMapper; $this->folderMapper = $folderMapper; $this->mailAccountMapper = $mailAccountMapper; $this->imapClientFactory = $imapClientFactory; $this->timeFactory = $timeFactory; - $this->logger = $logger; } /** * @throws ServiceException */ - public function sync(Account $account, bool $force = false): void { + public function sync(Account $account, + LoggerInterface $logger, + bool $force = false): void { if (!$force && $account->getMailAccount()->getLastMailboxSync() >= ($this->timeFactory->getTime() - 7200)) { - $this->logger->debug("account is up to date, skipping mailbox sync"); + $logger->debug("account is up to date, skipping mailbox sync"); return; } @@ -92,7 +89,7 @@ class MailboxSync { $this->getPersonalNamespace($namespaces) ); } catch (Horde_Imap_Client_Exception $e) { - $this->logger->debug('Getting namespaces for account ' . $account->getId() . ' failed: ' . $e->getMessage()); + $logger->debug('Getting namespaces for account ' . $account->getId() . ' failed: ' . $e->getMessage()); } try { diff --git a/lib/IMAP/Threading/ThreadBuilder.php b/lib/IMAP/Threading/ThreadBuilder.php index 8053d045d..173277d20 100644 --- a/lib/IMAP/Threading/ThreadBuilder.php +++ b/lib/IMAP/Threading/ThreadBuilder.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\Mail\IMAP\Threading; use OCA\Mail\Support\PerformanceLogger; +use Psr\Log\LoggerInterface; use function array_key_exists; use function count; @@ -43,8 +44,11 @@ class ThreadBuilder { * * @return Container[] */ - public function build(array $messages): array { - $log = $this->performanceLogger->start('Threading ' . count($messages) . ' messages'); + public function build(array $messages, LoggerInterface $logger): array { + $log = $this->performanceLogger->startWithLogger( + 'Threading ' . count($messages) . ' messages', + $logger + ); // Step 1 $idTable = $this->buildIdTable($messages); |