Skip to content

Commit

Permalink
Only show the first 200 chars max in the error log
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 committed Sep 19, 2024
1 parent 4c81dc8 commit 7e646dc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Service/ActivityPub/ApHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,21 @@ private function logRequestException(?ResponseInterface $response, string $reque
}
}

// Often 400, 404 errors just return the full HTML page, so we don't want to log the content of them
$this->logger->error('{type} get fail: {address}, ex: {e}: {msg}', [
// Often 400, 404 errors just return the full HTML page, so we don't want to log the full content of them
// We truncate the content to 200 characters max.
$this->logger->error('{type} get fail: {address}, ex: {e}: {msg}. Truncated content: {content}', [
'type' => $requestType,
'address' => $requestUrl,
'e' => \get_class($e),
'msg' => $e->getMessage(),
'content' => substr($content, 0, 200) ?? 'No content provided',
]);
// Therefore, we only log the content in debug log mode
$this->logger->debug('Response body content: {content}', [
'content' => $content ?? 'No content provided',
]);
// And only log the full content in debug log mode
if ($content) {
$this->logger->debug('Full response body content: {content}', [
'content' => $content,
]);
}
throw $e;
}

Expand Down

0 comments on commit 7e646dc

Please sign in to comment.