Updated Logging System to Include Application Logs

This commit is contained in:
2026-06-08 12:25:47 -05:00
parent 15e93c1e45
commit 9a9f890494
13 changed files with 323 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
const nodemailer = require('nodemailer');
const { all, audit, now, run } = require('../db');
const { logEvent } = require('../logger');
function readSettings() {
const rows = all('SELECT key, value FROM app_settings');
@@ -95,13 +96,20 @@ async function sendMail({ to, subject, html, text }) {
throw Object.assign(new Error('No recipients are configured'), { status: 400 });
}
const transport = getTransport();
return transport.sendMail({
from: c.from || c.user,
to: recipients.join(', '),
subject,
html,
text
});
try {
const info = await transport.sendMail({
from: c.from || c.user,
to: recipients.join(', '),
subject,
html,
text
});
logEvent('smtp', `Email sent: "${subject}" to ${recipients.length} recipient(s)`, { subject, recipients: recipients.length, host: c.host, messageId: info.messageId });
return info;
} catch (error) {
logEvent('smtp', `Email send failed: "${subject}" — ${error.message}`, { subject, recipients: recipients.length, host: c.host }, 'error');
throw error;
}
}
async function sendTestEmail(to, userId) {