Merge pull request #10438 from appwrite/chore-beautify-certificate-logs

Add colors to certificate logs
This commit is contained in:
Matej Bačo 2025-09-11 12:32:58 +02:00 committed by GitHub
commit 485dd0a1e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -174,6 +174,9 @@ class Certificates extends Action
$success = false;
try {
$date = \date('H:i:s');
$certificate->setAttribute('logs', "\033[90m[{$date}] \033[97mCertificate generation started. \033[0m\n");
// Validate domain and DNS records. Skip if job is forced
if (!$skipRenewCheck) {
$mainDomain = $validationDomain ?? $this->getMainDomain();
@ -201,9 +204,11 @@ class Certificates extends Action
$success = true;
} catch (Throwable $e) {
$logs = $e->getMessage();
$currentLogs = $certificate->getAttribute('logs', '');
$date = \date('H:i:s');
$errorMessage = "\033[90m[{$date}] \033[31mCertificate generation failed: \033[0m\n";
// Set exception as log in certificate document
$certificate->setAttribute('logs', \mb_strcut($logs, 0, 1000000));// Limit to 1MB
$certificate->setAttribute('logs', $currentLogs . $errorMessage . \mb_strcut($logs, 0, 500000));// Limit to 500kb
// Increase attempts count
$attempts = $certificate->getAttribute('attempts', 0) + 1;