Skip to content

Commit

Permalink
Add remaining prefixes to logger on important files (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Nov 27, 2024
1 parent 5535997 commit 8f7b0ba
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 98 deletions.
6 changes: 3 additions & 3 deletions src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function registerPushNotifications(#[MapRequestPayload] RegisterPushReque

return new JsonResponse();
} catch (\ErrorException $e) {
$this->logger->error('There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
$this->logger->error('[AjaxController::handle] There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
'e' => \get_class($e),
'm' => $e->getMessage(),
'o' => json_encode($e),
Expand All @@ -295,7 +295,7 @@ public function unregisterPushNotifications(#[MapRequestPayload] UnRegisterPushR

return new JsonResponse();
} catch (\Exception $e) {
$this->logger->error('There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
$this->logger->error('[AjaxController::unregisterPushNotifications] There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
'e' => \get_class($e),
'm' => $e->getMessage(),
'o' => json_encode($e),
Expand All @@ -313,7 +313,7 @@ public function testPushNotification(#[MapRequestPayload] TestPushRequestPayload

return new JsonResponse();
} catch (\ErrorException $e) {
$this->logger->error('There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
$this->logger->error('[AjaxController::testPushNotification] There was an exception while deleting a UserPushSubscription: {e} - {m}. {o}', [
'e' => \get_class($e),
'm' => $e->getMessage(),
'o' => json_encode($e),
Expand Down
16 changes: 8 additions & 8 deletions src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public function doWork(MessageInterface $message): void
$payload = @json_decode($message->payload, true);

if (null === $payload) {
$this->logger->warning('Activity message from was empty: {json}, ignoring it', ['json' => json_encode($message->payload)]);
$this->logger->warning('[ActivityHandler::doWork] Activity message from was empty: {json}, ignoring it', ['json' => json_encode($message->payload)]);
throw new UnrecoverableMessageHandlingException('activity message from was empty');
}

if ($message->request && $message->headers) {
try {
$this->signatureValidator->validate($message->request, $message->headers, $message->payload);
} catch (InboxForwardingException $exception) {
$this->logger->info("The message was forwarded by {receivedFrom}. Dispatching a new activity message '{origin}'", ['receivedFrom' => $exception->receivedFrom, 'origin' => $exception->realOrigin]);
$this->logger->info("[ActivityHandler::doWork] The message was forwarded by {receivedFrom}. Dispatching a new activity message '{origin}'", ['receivedFrom' => $exception->receivedFrom, 'origin' => $exception->realOrigin]);
if (!$this->settingsManager->isBannedInstance($exception->realOrigin)) {
$body = $this->apHttpClient->getActivityObject($exception->realOrigin, false);
$this->bus->dispatch(new ActivityMessage($body));
Expand All @@ -83,14 +83,14 @@ public function doWork(MessageInterface $message): void

return;
} catch (InvalidUserPublicKeyException $exception) {
$this->logger->warning("Unable to extract public key for '{user}'.", ['user' => $exception->apProfileId]);
$this->logger->warning("[ActivityHandler::doWork] Unable to extract public key for '{user}'.", ['user' => $exception->apProfileId]);

return;
}
}

if (null === $payload['id']) {
$this->logger->warning('activity message has no id field which is required: {json}', ['json' => json_encode($message->payload)]);
$this->logger->warning('[ActivityHandler::doWork] Activity message has no id field which is required: {json}', ['json' => json_encode($message->payload)]);
throw new UnrecoverableMessageHandlingException('activity message has no id field');
}

Expand Down Expand Up @@ -130,7 +130,7 @@ public function doWork(MessageInterface $message): void
$user = $this->manager->findActorOrCreate($payload['id']);
}
} catch (\Exception $e) {
$this->logger->error('payload: '.json_encode($payload));
$this->logger->error('[ActivityHandler::doWork] Payload: '.json_encode($payload));

return;
}
Expand All @@ -140,7 +140,7 @@ public function doWork(MessageInterface $message): void
}

if (null === $user) {
$this->logger->warning('Could not find an actor discarding ActivityMessage {m}', ['m' => $message->payload]);
$this->logger->warning('[ActivityHandler::doWork] Could not find an actor discarding ActivityMessage {m}', ['m' => $message->payload]);

return;
}
Expand Down Expand Up @@ -172,15 +172,15 @@ private function handle(?array $payload)
$user = $this->manager->findActorOrCreate($actor);
if ($user instanceof User && null === $user->apId) {
// don't do anything if we get an announce activity for something a local user did (unless it's a boost, see comment above)
$this->logger->warning('ignoring this message because it announces an activity from a local user');
$this->logger->warning('[ActivityHandler::handle] Ignoring this message because it announces an activity from a local user');

return;
}
}
}
}

$this->logger->debug('Got activity message of type {type}: {message}', ['type' => $payload['type'], 'message' => json_encode($payload)]);
$this->logger->debug('[ActivityHandler::handle] Got activity message of type {type}: {message}', ['type' => $payload['type'], 'message' => json_encode($payload)]);

switch ($payload['type']) {
case 'Create':
Expand Down
6 changes: 3 additions & 3 deletions src/MessageHandler/ActivityPub/Inbox/AddHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function handleModeratorAdd(Magazine $targetMag, Magazine|User $actor, $o

return;
}
$this->logger->info('"{actor}" ({actorId}) added "{added}" ({addedId}) as moderator to "{magName}" ({magId})', [
$this->logger->info('[AddHandler::handleModeratorAdd] "{actor}" ({actorId}) added "{added}" ({addedId}) as moderator to "{magName}" ({magId})', [
'actor' => $actor->username,
'actorId' => $actor->getId(),
'added' => $object->username,
Expand Down Expand Up @@ -120,7 +120,7 @@ private function handlePinnedAdd(Magazine $targetMag, User $actor, mixed $object
if (Entry::class === $pair['type']) {
$existingEntry = $this->entryRepository->findOneBy(['id' => $pair['id']]);
if ($existingEntry && !$existingEntry->sticky) {
$this->logger->info('pinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->logger->info('[AddHandler::handlePinnedAdd] Pinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->entryManager->pin($existingEntry, $actor);
}
}
Expand All @@ -131,7 +131,7 @@ private function handlePinnedAdd(Magazine $targetMag, User $actor, mixed $object
$this->apHttpClient->invalidateCollectionObjectCache($existingEntry->magazine->apFeaturedUrl);
}
if (!$existingEntry->sticky) {
$this->logger->info('pinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->logger->info('[AddHandler::handlePinnedAdd] Pinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->entryManager->pin($existingEntry, $actor);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/ActivityPub/Inbox/AnnounceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function doWork(MessageInterface $message): void
}
$chainDispatchCallback = function (array $object, ?string $adjustedUrl) use ($message) {
if ($adjustedUrl) {
$this->logger->info('got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$this->logger->info('[AnnounceHandler::doWork] Got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$message->payload['object'] = $adjustedUrl;
}
$this->bus->dispatch(new ChainActivityMessage([$object], announce: $message->payload));
Expand Down
16 changes: 8 additions & 8 deletions src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function doWork(MessageInterface $message): void
$validObjectTypes = ['Page', 'Note', 'Article', 'Question', 'Video'];
$object = $message->chain[0];
if (!\in_array($object['type'], $validObjectTypes)) {
$this->logger->error('Cannot get the dependencies of the object, its type {t} is not one we can handle. {m]', ['t' => $object['type'], 'm' => $message]);
$this->logger->error('[ChainActivityHandler::doWork] Cannot get the dependencies of the object, its type {t} is not one we can handle. {m]', ['t' => $object['type'], 'm' => $message]);

return;
}
Expand All @@ -75,7 +75,7 @@ public function doWork(MessageInterface $message): void
}

if (!$entity) {
$this->logger->error('Could not retrieve all the dependencies of {o}', ['o' => $object['id']]);
$this->logger->error('[ChainActivityHandler::doWork] Could not retrieve all the dependencies of {o}', ['o' => $object['id']]);

return;
}
Expand Down Expand Up @@ -104,12 +104,12 @@ private function retrieveObject(string $apUrl): Entry|EntryComment|Post|PostComm
try {
$object = $this->client->getActivityObject($apUrl);
if (!$object) {
$this->logger->warning('Got an empty object for {url}', ['url' => $apUrl]);
$this->logger->warning('[ChainActivityHandler::retrieveObject] Got an empty object for {url}', ['url' => $apUrl]);

return null;
}
if (!\is_array($object)) {
$this->logger->warning("Didn't get an array for {url}. Got '{val}' instead, exiting", ['url' => $apUrl, 'val' => $object]);
$this->logger->warning("[ChainActivityHandler::retrieveObject] Didn't get an array for {url}. Got '{val}' instead, exiting", ['url' => $apUrl, 'val' => $object]);

return null;
}
Expand All @@ -122,7 +122,7 @@ private function retrieveObject(string $apUrl): Entry|EntryComment|Post|PostComm
}
$meta = $this->repository->findByObjectId($parentUrl);
if (!$meta) {
$this->logger->warning('fetching the parent object ({parent}) did not work for {url}, aborting', ['parent' => $parentUrl, 'url' => $apUrl]);
$this->logger->warning('[ChainActivityHandler::retrieveObject] Fetching the parent object ({parent}) did not work for {url}, aborting', ['parent' => $parentUrl, 'url' => $apUrl]);

return null;
}
Expand All @@ -131,17 +131,17 @@ private function retrieveObject(string $apUrl): Entry|EntryComment|Post|PostComm
switch ($object['type']) {
case 'Question':
case 'Note':
$this->logger->debug('creating note {o}', ['o' => $object]);
$this->logger->debug('[ChainActivityHandler::retrieveObject] Creating note {o}', ['o' => $object]);

return $this->note->create($object);
case 'Page':
case 'Article':
case 'Video':
$this->logger->debug('creating page {o}', ['o' => $object]);
$this->logger->debug('[ChainActivityHandler::retrieveObject] Creating page {o}', ['o' => $object]);

return $this->page->create($object);
default:
$this->logger->warning('Could not create an object from type {t} on {url}: {o}', ['t' => $object['type'], 'url' => $apUrl, 'o' => $object]);
$this->logger->warning('[ChainActivityHandler::retrieveObject] Could not create an object from type {t} on {url}: {o}', ['t' => $object['type'], 'url' => $apUrl, 'o' => $object]);
}
} catch (UserBannedException) {
$this->logger->info('[ChainActivityHandler::retrieveObject] The user is banned, url: {url}', ['url' => $apUrl]);
Expand Down
10 changes: 5 additions & 5 deletions src/MessageHandler/ActivityPub/Inbox/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public function doWork(MessageInterface $message): void
$this->handlePage($object, $stickyIt);
}
} catch (UserBannedException) {
$this->logger->info('Did not create the post, because the user is banned');
$this->logger->info('[CreateHandler::handleModeratorAdd] Did not create the post, because the user is banned');
} catch (UserDeletedException) {
$this->logger->info('Did not create the post, because the user is deleted');
$this->logger->info('[CreateHandler::handleModeratorAdd] Did not create the post, because the user is deleted');
} catch (TagBannedException) {
$this->logger->info('Did not create the post, because one of the used tags is banned');
$this->logger->info('[CreateHandler::handleModeratorAdd] Did not create the post, because one of the used tags is banned');
} catch (PostingRestrictedException $e) {
if ($e->actor instanceof User) {
$username = $e->actor->getUsername();
} else {
$username = $e->actor->name;
}
$this->logger->info('Did not create the post, because the magazine {m} restricts posting to mods and {u} is not a mod', ['m' => $e->magazine, 'u' => $username]);
$this->logger->info('[CreateHandler::handleModeratorAdd] Did not create the post, because the magazine {m} restricts posting to mods and {u} is not a mod', ['m' => $e->magazine, 'u' => $username]);
} catch (InstanceBannedException $e) {
$this->logger->info('Did not create the post, because the user\'s instance is banned');
$this->logger->info('[CreateHandler::handleModeratorAdd] Did not create the post, because the user\'s instance is banned');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/ActivityPub/Inbox/DislikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function doWork(MessageInterface $message): void

$chainDispatchCallback = function (array $object, ?string $adjustedUrl) use ($message) {
if ($adjustedUrl) {
$this->logger->info('got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$this->logger->info('[DislikeHandler::doWork] got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$message->payload['object'] = $adjustedUrl;
}
$this->bus->dispatch(new ChainActivityMessage([$object], dislike: $message->payload));
Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/ActivityPub/Inbox/LikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function doWork(MessageInterface $message): void

$chainDispatchCallback = function (array $object, ?string $adjustedUrl) use ($message) {
if ($adjustedUrl) {
$this->logger->info('got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$this->logger->info('[LikeHandler::doWork] Got an adjusted url: {url}, using that instead of {old}', ['url' => $adjustedUrl, 'old' => $message->payload['object']['id'] ?? $message->payload['object']]);
$message->payload['object'] = $adjustedUrl;
}
$this->bus->dispatch(new ChainActivityMessage([$object], like: $message->payload));
Expand Down
6 changes: 3 additions & 3 deletions src/MessageHandler/ActivityPub/Inbox/RemoveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function handleModeratorRemove($object1, Magazine $targetMag, Magazine|Us
return;
}

$this->logger->info(' "{actor}" ({actorId}) removed "{removed}" ({removedId}) as moderator from "{magName}" ({magId})', [
$this->logger->info('[RemoveHandler::handleModeratorRemove] "{actor}" ({actorId}) removed "{removed}" ({removedId}) as moderator from "{magName}" ({magId})', [
'actor' => $actor->username,
'actorId' => $actor->getId(),
'removed' => $object->username,
Expand Down Expand Up @@ -121,14 +121,14 @@ private function handlePinnedRemove(mixed $object, Magazine $targetMag, User $ac
if (Entry::class === $pair['type']) {
$existingEntry = $this->entryRepository->findOneBy(['id' => $pair['id']]);
if ($existingEntry && $existingEntry->sticky) {
$this->logger->info('unpinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->logger->info('[RemoveHandler::handlePinnedRemove] Unpinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->entryManager->pin($existingEntry, $actor);
}
}
} else {
$existingEntry = $this->entryRepository->findOneBy(['apId' => $apId]);
if ($existingEntry && $existingEntry->sticky) {
$this->logger->info('unpinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->logger->info('[RemoveHandler::handlePinnedRemove] Unpinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->entryManager->pin($existingEntry, $actor);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Outbox/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function doWork(MessageInterface $message): void

if ($entity instanceof Message) {
$receivers = $this->messageManager->findAudience($entity->thread);
$this->logger->info('sending message to {p}', ['p' => $receivers]);
$this->logger->info('[CreateHandler::doWork] sending message to {p}', ['p' => $receivers]);
} else {
$receivers = [
...$this->userRepository->findAudience($entity->user),
Expand All @@ -66,7 +66,7 @@ public function doWork(MessageInterface $message): void
// only add the magazine subscribers if it is not the random magazine
$receivers = array_merge($receivers, $this->magazineRepository->findAudience($entity->magazine));
}
$this->logger->debug('sending create activity to {p}', ['p' => $receivers]);
$this->logger->debug('[CreateHandler::doWork] Sending create activity to {p}', ['p' => $receivers]);
}
$this->deliverManager->deliver(array_filter(array_unique($receivers)), $activity);
}
Expand Down
6 changes: 3 additions & 3 deletions src/MessageHandler/ActivityPub/Outbox/FlagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function doWork(MessageInterface $message): void
if (!($message instanceof FlagMessage)) {
throw new \LogicException();
}
$this->logger->debug('got a FlagMessage');
$this->logger->debug('[FlagHandler::doWork] Got a FlagMessage');
$report = $this->reportRepository->find($message->reportId);
$this->logger->debug('found the report: '.json_encode($report));
$this->logger->debug('[FlagHandler::doWork] Found the report: '.json_encode($report));
$inboxes = $this->getInboxUrls($report);
if (0 === \sizeof($inboxes)) {
$this->logger->info("couldn't find any inboxes to send the FlagMessage to");
$this->logger->info("[FlagHandler::doWork] couldn't find any inboxes to send the FlagMessage to");

return;
}
Expand Down
Loading

0 comments on commit 8f7b0ba

Please sign in to comment.