Merge pull request #14739 from MrPetovan/bug/14711-log-new-line

Remove potential new lines in reported logger instances
This commit is contained in:
Michael Vogel 2025-01-28 21:05:59 +01:00 committed by GitHub
commit d5652ade63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 134 additions and 105 deletions

View file

@ -15,7 +15,6 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory; use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
@ -205,7 +204,7 @@ class Notify extends BaseRepository
* @return bool * @return bool
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
function createFromArray($params) public function createFromArray($params)
{ {
/** @var string the common prefix of a notification subject */ /** @var string the common prefix of a notification subject */
$subjectPrefix = $this->l10n->t('[Friendica:Notify]'); $subjectPrefix = $this->l10n->t('[Friendica:Notify]');
@ -340,7 +339,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s %s posted to your profile wall', $subjectPrefix, $params['source_name']); $subject = $l10n->t('%s %s posted to your profile wall', $subjectPrefix, $params['source_name']);
$preamble = $l10n->t('%1$s posted to your profile wall at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('%1$s posted to your profile wall at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('%1$s posted to [url=%2$s]your wall[/url]', $epreamble = $l10n->t(
'%1$s posted to [url=%2$s]your wall[/url]',
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
$params['link'] $params['link']
); );
@ -356,7 +356,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s Introduction received', $subjectPrefix); $subject = $l10n->t('%s Introduction received', $subjectPrefix);
$preamble = $l10n->t('You\'ve received an introduction from \'%1$s\' at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('You\'ve received an introduction from \'%1$s\' at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You\'ve received [url=%1$s]an introduction[/url] from %2$s.', $epreamble = $l10n->t(
'You\'ve received [url=%1$s]an introduction[/url] from %2$s.',
$itemlink, $itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
); );
@ -373,7 +374,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s A new person is sharing with you', $subjectPrefix); $subject = $l10n->t('%s A new person is sharing with you', $subjectPrefix);
$preamble = $l10n->t('%1$s is sharing with you at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('%1$s is sharing with you at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('%1$s is sharing with you at %2$s', $epreamble = $l10n->t(
'%1$s is sharing with you at %2$s',
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
$sitename $sitename
); );
@ -383,7 +385,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s You have a new follower', $subjectPrefix); $subject = $l10n->t('%s You have a new follower', $subjectPrefix);
$preamble = $l10n->t('You have a new follower at %2$s : %1$s', $params['source_name'], $sitename); $preamble = $l10n->t('You have a new follower at %2$s : %1$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You have a new follower at %2$s : %1$s', $epreamble = $l10n->t(
'You have a new follower at %2$s : %1$s',
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
$sitename $sitename
); );
@ -399,7 +402,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s Friend suggestion received', $subjectPrefix); $subject = $l10n->t('%s Friend suggestion received', $subjectPrefix);
$preamble = $l10n->t('You\'ve received a friend suggestion from \'%1$s\' at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('You\'ve received a friend suggestion from \'%1$s\' at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.', $epreamble = $l10n->t(
'You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.',
$itemlink, $itemlink,
'[url='.$params['item']['url'].']'.$params['item']['name'].'[/url]', '[url='.$params['item']['url'].']'.$params['item']['name'].'[/url]',
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
@ -420,7 +424,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s Connection accepted', $subjectPrefix); $subject = $l10n->t('%s Connection accepted', $subjectPrefix);
$preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('%2$s has accepted your [url=%1$s]connection request[/url].', $epreamble = $l10n->t(
'%2$s has accepted your [url=%1$s]connection request[/url].',
$itemlink, $itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
); );
@ -435,7 +440,8 @@ class Notify extends BaseRepository
$subject = $l10n->t('%s Connection accepted', $subjectPrefix); $subject = $l10n->t('%s Connection accepted', $subjectPrefix);
$preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('%2$s has accepted your [url=%1$s]connection request[/url].', $epreamble = $l10n->t(
'%2$s has accepted your [url=%1$s]connection request[/url].',
$itemlink, $itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
); );
@ -457,14 +463,17 @@ class Notify extends BaseRepository
$subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request'); $subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request');
$preamble = $l10n->t('You\'ve received a registration request from \'%1$s\' at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('You\'ve received a registration request from \'%1$s\' at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You\'ve received a [url=%1$s]registration request[/url] from %2$s.', $epreamble = $l10n->t(
'You\'ve received a [url=%1$s]registration request[/url] from %2$s.',
$itemlink, $itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
); );
$body = $l10n->t("Display Name: %s\nSite Location: %s\nLogin Name: %s (%s)", $body = $l10n->t(
"Display Name: %s\nSite Location: %s\nLogin Name: %s (%s)",
$params['source_name'], $params['source_name'],
$siteurl, $params['source_mail'], $siteurl,
$params['source_mail'],
$params['source_nick'] $params['source_nick']
); );
@ -478,14 +487,17 @@ class Notify extends BaseRepository
$subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('new registration'); $subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('new registration');
$preamble = $l10n->t('You\'ve received a new registration from \'%1$s\' at %2$s', $params['source_name'], $sitename); $preamble = $l10n->t('You\'ve received a new registration from \'%1$s\' at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You\'ve received a [url=%1$s]new registration[/url] from %2$s.', $epreamble = $l10n->t(
'You\'ve received a [url=%1$s]new registration[/url] from %2$s.',
$itemlink, $itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]' '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
); );
$body = $l10n->t("Display Name: %s\nSite Location: %s\nLogin Name: %s (%s)", $body = $l10n->t(
"Display Name: %s\nSite Location: %s\nLogin Name: %s (%s)",
$params['source_name'], $params['source_name'],
$siteurl, $params['source_mail'], $siteurl,
$params['source_mail'],
$params['source_nick'] $params['source_nick']
); );
@ -599,9 +611,7 @@ class Notify extends BaseRepository
DBA::insert('notify-threads', $fields); DBA::insert('notify-threads', $fields);
$emailBuilder->setHeader('Message-ID', $message_id); $emailBuilder->setHeader('Message-ID', $message_id);
$log_msg = "No previous notification found for this parent:\n" . $this->logger->info('No previous notification found for this parent', ['parent' => $params['parent'], 'uid' => $params['uid']]);
" parent: {$params['parent']}\n" . " uid : {$params['uid']}\n";
$this->logger->info($log_msg);
} else { } else {
// If not, just "follow" the thread. // If not, just "follow" the thread.
$emailBuilder->setHeader('References', $message_id); $emailBuilder->setHeader('References', $message_id);
@ -645,7 +655,8 @@ class Notify extends BaseRepository
$emailBuilder->withPhoto( $emailBuilder->withPhoto(
$datarray['source_photo'], $datarray['source_photo'],
$datarray['source_link'] ?? $sitelink, $datarray['source_link'] ?? $sitelink,
$datarray['source_name'] ?? $sitename); $datarray['source_name'] ?? $sitename
);
} }
$email = $emailBuilder->build(); $email = $emailBuilder->build();
@ -725,9 +736,12 @@ class Notify extends BaseRepository
$params['source_photo'] = $contact['photo']; $params['source_photo'] = $contact['photo'];
} }
$item = Model\Post::selectFirstForUser($Notification->uid, Model\Item::ITEM_FIELDLIST, $item = Model\Post::selectFirstForUser(
$Notification->uid,
Model\Item::ITEM_FIELDLIST,
['uid' => [0, $Notification->uid], 'uri-id' => $Notification->targetUriId, 'deleted' => false], ['uid' => [0, $Notification->uid], 'uri-id' => $Notification->targetUriId, 'deleted' => false],
['order' => ['uid' => true]]); ['order' => ['uid' => true]]
);
if (empty($item)) { if (empty($item)) {
$this->logger->info('Item not found', ['uri-id' => $Notification->targetUriId, 'type' => $Notification->type]); $this->logger->info('Item not found', ['uri-id' => $Notification->targetUriId, 'type' => $Notification->type]);
return false; return false;

View file

@ -310,7 +310,7 @@ class Delivery
$atom = DFRN::entries($msgitems, $owner); $atom = DFRN::entries($msgitems, $owner);
} }
DI::logger()->debug('Notifier entry: ' . $contact['url'] . ' ' . ($target_item_id ?? 'relocation') . ' entry: ' . $atom); DI::logger()->debug('Notifier entry', ['url' => $contact['url'], 'target_item_id' => ($target_item_id ?? 'relocation'), 'entry' => $atom]);
$protocol = Post\DeliveryData::DFRN; $protocol = Post\DeliveryData::DFRN;

View file

@ -2790,7 +2790,7 @@ class Diaspora
*/ */
public static function encodePrivateData(string $msg, array $user, array $contact, string $prvkey, string $pubkey): string public static function encodePrivateData(string $msg, array $user, array $contact, string $prvkey, string $pubkey): string
{ {
DI::logger()->debug('Message: ' . $msg); DI::logger()->debug('Diaspora message', ['msg' => $msg]);
// without a public key nothing will work // without a public key nothing will work
if (!$pubkey) { if (!$pubkey) {

View file

@ -40,9 +40,13 @@ class Emailer
/** @var string */ /** @var string */
private $siteEmailName; private $siteEmailName;
public function __construct(IManageConfigValues $config, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, LoggerInterface $logger, public function __construct(
L10n $defaultLang) IManageConfigValues $config,
{ IManagePersonalConfigValues $pConfig,
BaseURL $baseURL,
LoggerInterface $logger,
L10n $defaultLang
) {
$this->config = $config; $this->config = $config;
$this->pConfig = $pConfig; $this->pConfig = $pConfig;
$this->logger = $logger; $this->logger = $logger;
@ -89,8 +93,14 @@ class Emailer
*/ */
public function newSystemMail() public function newSystemMail()
{ {
return new SystemMailBuilder($this->l10n, $this->baseUrl, $this->config, $this->logger, return new SystemMailBuilder(
$this->getSiteEmailAddress(), $this->getSiteEmailName()); $this->l10n,
$this->baseUrl,
$this->config,
$this->logger,
$this->getSiteEmailAddress(),
$this->getSiteEmailName()
);
} }
/** /**
@ -100,8 +110,14 @@ class Emailer
*/ */
public function newNotifyMail() public function newNotifyMail()
{ {
return new NotifyMailBuilder($this->l10n, $this->baseUrl, $this->config, $this->logger, return new NotifyMailBuilder(
$this->getSiteEmailAddress(), $this->getSiteEmailName()); $this->l10n,
$this->baseUrl,
$this->config,
$this->logger,
$this->getSiteEmailAddress(),
$this->getSiteEmailName()
);
} }
/** /**
@ -207,8 +223,7 @@ class Emailer
$hookdata['parameters'] $hookdata['parameters']
); );
$this->logger->debug('header ' . 'To: ' . $email->getToAddress() . '\n' . $messageHeader); $this->logger->debug('Email message header', ['To' => $email->getToAddress(), 'messageHeader' => $messageHeader, 'return' => ($res) ? 'true' : 'false']);
$this->logger->debug('return value ' . (($res) ? 'true' : 'false'));
return $res; return $res;
} }