Streamline log lines

This commit is contained in:
Matthew Exon 2024-06-29 15:23:24 +02:00
parent d3dcd5428c
commit 5f27f72b0d

View file

@ -34,7 +34,7 @@ function mailstream_install()
Hook::register('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
Hook::register('mailstream_send_hook', 'addon/mailstream/mailstream.php', 'mailstream_send_hook');
Logger::info("mailstream: installed");
Logger::info("installed mailstream");
}
/**
@ -44,7 +44,7 @@ function mailstream_check_version()
{
if (!is_null(DI::config()->get('mailstream', 'dbversion'))) {
DI::config()->delete('mailstream', 'dbversion');
Logger::info("mailstream_check_version: old version detected, reinstalling");
Logger::info("old version detected, reinstalling");
mailstream_install();
Hook::loadHooks();
Hook::add(
@ -105,7 +105,7 @@ function mailstream_generate_id(string $uri): string
$host = DI::baseUrl()->getHost();
$resource = hash('md5', $uri);
$message_id = "<" . $resource . "@" . $host . ">";
Logger::debug('mailstream: Generated message ID ' . $message_id . ' for URI ' . $uri);
Logger::debug('generated message ID', ['id' => $message_id, 'uri' => $uri]);
return $message_id;
}
@ -114,20 +114,20 @@ function mailstream_send_hook(array $data)
$criteria = array('uid' => $data['uid'], 'contact-id' => $data['contact-id'], 'uri' => $data['uri']);
$item = Post::selectFirst([], $criteria);
if (empty($item)) {
Logger::error('mailstream_send_hook could not find item');
Logger::error('could not find item');
return;
}
$user = User::getById($item['uid']);
if (empty($user)) {
Logger::error('mailstream_send_hook could not fund user', ['uid' => $item['uid']]);
Logger::error('could not find user', ['uid' => $item['uid']]);
return;
}
if (!mailstream_send($data['message_id'], $item, $user)) {
Logger::debug('mailstream_send_hook send failed, will retry', $data);
Logger::debug('send failed, will retry', $data);
if (!Worker::defer()) {
Logger::error('mailstream_send_hook failed and could not defer', $data);
Logger::error('failed and could not defer', $data);
}
}
}
@ -145,32 +145,32 @@ function mailstream_post_hook(array &$item)
mailstream_check_version();
if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) {
Logger::debug('mailstream: not enabled.', ['item' => $item['id'], ' uid ' => $item['uid']]);
Logger::debug('mailstream not enabled.', ['item' => $item['id'], 'uid' => $item['uid']]);
return;
}
if (!$item['uid']) {
Logger::debug('mailstream: no uid for item ' . $item['id']);
Logger::debug('no uid', ['item' => $item['id']]);
return;
}
if (!$item['contact-id']) {
Logger::debug('mailstream: no contact-id for item ' . $item['id']);
Logger::debug('no contact-id', ['item' => $item['id']]);
return;
}
if (!$item['uri']) {
Logger::debug('mailstream: no uri for item ' . $item['id']);
Logger::debug('no uri', ['item' => $item['id']]);
return;
}
if ($item['verb'] == Activity::ANNOUNCE) {
Logger::debug('mailstream: announce item ', ['item' => $item['id']]);
Logger::debug('ignoring announce', ['item' => $item['id']]);
return;
}
if (DI::pConfig()->get($item['uid'], 'mailstream', 'nolikes')) {
if ($item['verb'] == Activity::LIKE) {
Logger::debug('mailstream: like item ' . $item['id']);
Logger::debug('ignoring like', ['item' => $item['id']]);
return;
}
if ($item['verb'] == Activity::DISLIKE) {
Logger::debug('mailstream: dislike item ' . $item['id']);
Logger::debug('ignoring dislike', ['item' => $item['id']]);
return;
}
}
@ -221,7 +221,7 @@ function mailstream_do_images(array &$item, array &$attachments)
try {
$curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar);
} catch (InvalidArgumentException $e) {
Logger::error('mailstream_do_images exception fetching url', ['url' => $url, 'item_id' => $item['id']]);
Logger::error('exception fetching url', ['url' => $url, 'item_id' => $item['id']]);
continue;
}
$attachments[$url] = [
@ -322,13 +322,12 @@ function mailstream_subject(array $item): string
}
$contact = Contact::selectFirst([], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
if (!DBA::isResult($contact)) {
Logger::error(
'mailstream_subject no contact for item',
['id' => $item['id'],
Logger::error('no contact', [
'item' => $item['id'],
'plink' => $item['plink'],
'contact id' => $item['contact-id'],
'uid' => $item['uid']]
);
'uid' => $item['uid']
]);
return DI::l10n()->t("Friendica post");
}
if ($contact['network'] === 'dfrn') {
@ -365,17 +364,16 @@ function mailstream_subject(array $item): string
function mailstream_send(string $message_id, array $item, array $user): bool
{
if (!is_array($item)) {
Logger::error('mailstream_send item is empty', ['message_id' => $message_id]);
Logger::error('item is empty', ['message_id' => $message_id]);
return false;
}
if (!$item['visible']) {
Logger::debug('mailstream_send item not yet visible', ['item uri' => $item['uri']]);
Logger::debug('item not yet visible', ['item uri' => $item['uri']]);
return false;
}
if (!$message_id) {
Logger::error('mailstream_send no message ID supplied', ['item uri' => $item['uri'],
'user email' => $user['email']]);
Logger::error('no message ID supplied', ['item uri' => $item['uri'], 'user email' => $user['email']]);
return true;
}
@ -432,13 +430,15 @@ function mailstream_send(string $message_id, array $item, array $user): bool
if (!$mail->Send()) {
throw new Exception($mail->ErrorInfo);
}
Logger::debug('mailstream_send sent message', ['message ID' => $mail->MessageID,
Logger::debug('sent message', [
'message ID' => $mail->MessageID,
'subject' => $mail->Subject,
'address' => $address]);
'address' => $address
]);
} catch (phpmailerException $e) {
Logger::debug('mailstream_send PHPMailer exception sending message ' . $message_id . ': ' . $e->errorMessage());
Logger::debug('PHPMailer exception sending message', ['id' => $message_id, 'error' => $e->errorMessage()]);
} catch (Exception $e) {
Logger::debug('mailstream_send exception sending message ' . $message_id . ': ' . $e->getMessage());
Logger::debug('exception sending message', ['id' => $message_id, 'error' => $e->getMessage()]);
}
return true;
@ -468,7 +468,7 @@ function mailstream_html_wrap(string &$text)
function mailstream_convert_table_entries()
{
$ms_item_ids = DBA::selectToArray('mailstream_item', [], ['message-id', 'uri', 'uid', 'contact-id'], ["`mailstream_item`.`completed` IS NULL"]);
Logger::debug('mailstream_convert_table_entries processing ' . count($ms_item_ids) . ' items');
Logger::debug('processing items', ['count' => count($ms_item_ids)]);
foreach ($ms_item_ids as $ms_item_id) {
$send_hook_data = array('uid' => $ms_item_id['uid'],
'contact-id' => $ms_item_id['contact-id'],
@ -476,10 +476,10 @@ function mailstream_convert_table_entries()
'message_id' => $ms_item_id['message-id'],
'tries' => 0);
if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) {
Logger::info('mailstream_convert_table_entries: item has no message-id.', ['item' => $ms_item_id['id'], 'uri' => $ms_item_id['uri']]);
Logger::info('item has no message-id', ['item' => $ms_item_id['id'], 'uri' => $ms_item_id['uri']]);
continue;
}
Logger::info('mailstream_convert_table_entries: convert item to workerqueue', $send_hook_data);
Logger::info('convert item to workerqueue', $send_hook_data);
Hook::fork(Worker::PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data);
}
DBA::e('DROP TABLE `mailstream_item`');