Disable debug console logs for production

This commit is contained in:
Tola Leng
2025-07-14 15:45:05 +07:00
parent 0941250867
commit cb258d72c3
12 changed files with 88 additions and 88 deletions
@@ -10,7 +10,7 @@ import { toast } from "sonner";
* This should be called once per day
*/
export async function checkAllCertificatesAndNotify(): Promise<void> {
console.log("Starting daily SSL certificates check...");
// console.log("Starting daily SSL certificates check...");
try {
// Fetch all SSL certificates from database
@@ -18,16 +18,16 @@ export async function checkAllCertificatesAndNotify(): Promise<void> {
// Properly cast the items as SSLCertificate
const certificates = response.items as unknown as SSLCertificate[];
console.log(`Found ${certificates.length} certificates to check`);
// console.log(`Found ${certificates.length} certificates to check`);
// Check each certificate
for (const cert of certificates) {
await checkCertificateAndNotify(cert);
}
console.log("Daily SSL certificates check completed");
// console.log("Daily SSL certificates check completed");
} catch (error) {
console.error("Error during SSL certificates daily check:", error);
// console.error("Error during SSL certificates daily check:", error);
}
}
@@ -37,7 +37,7 @@ export async function checkAllCertificatesAndNotify(): Promise<void> {
* Note: SSL checking is now handled by the Go service, this function focuses on notifications
*/
export async function checkCertificateAndNotify(certificate: SSLCertificate): Promise<boolean> {
console.log(`Checking certificate for ${certificate.domain}...`);
// console.log(`Checking certificate for ${certificate.domain}...`);
try {
// Use the current certificate data (updated by Go service)
@@ -47,7 +47,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
const warningThreshold = Number(certificate.warning_threshold) || 30;
const expiryThreshold = Number(certificate.expiry_threshold) || 7;
console.log(`Certificate ${certificate.domain} thresholds: warning=${warningThreshold}, expiry=${expiryThreshold}, days left=${daysLeft}`);
// console.log(`Certificate ${certificate.domain} thresholds: warning=${warningThreshold}, expiry=${expiryThreshold}, days left=${daysLeft}`);
// Update status based on thresholds
const status = determineSSLStatus(daysLeft, warningThreshold, expiryThreshold);
@@ -67,7 +67,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
isCritical = false;
}
console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
// console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
// Update certificate status in database
await pb.collection('ssl_certificates').update(certificate.id, {
@@ -76,7 +76,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
// Send notification if needed
if (shouldNotify && certificate.notification_channel) {
console.log(`Sending notification for ${certificate.domain}`);
// console.log(`Sending notification for ${certificate.domain}`);
// Different message based on expiry threshold
const message = isCritical
@@ -92,28 +92,28 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
last_notified: new Date().toISOString()
});
console.log(`Notification sent for ${certificate.domain}`);
// console.log(`Notification sent for ${certificate.domain}`);
// Show toast for manual checks
toast.success(`Notification sent for ${certificate.domain}`);
return true;
} else {
console.error(`Failed to send notification for ${certificate.domain}`);
// console.error(`Failed to send notification for ${certificate.domain}`);
// Show error toast for manual checks
toast.error(`Failed to send notification for ${certificate.domain}`);
return false;
}
} else if (shouldNotify && !certificate.notification_channel) {
console.log(`No notification channel set for ${certificate.domain}, skipping notification`);
// console.log(`No notification channel set for ${certificate.domain}, skipping notification`);
toast.info(`No notification channel set for ${certificate.domain}, skipping notification`);
} else {
console.log(`No notification needed for ${certificate.domain} (${daysLeft} days left)`);
// console.log(`No notification needed for ${certificate.domain} (${daysLeft} days left)`);
// For manual checks, inform the user that thresholds weren't met
toast.info(`Certificate for ${certificate.domain} is valid (${daysLeft} days left)`);
}
return true;
} catch (error) {
console.error(`Error checking certificate for ${certificate.domain}:`, error);
// console.error(`Error checking certificate for ${certificate.domain}:`, error);
toast.error(`Error checking certificate: ${error instanceof Error ? error.message : "Unknown error"}`);
return false;
}