replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
+11
-11
@@ -4,13 +4,13 @@ import BoxError from './boxerror.js';
|
||||
import changelog from './changelog.js';
|
||||
import dashboard from './dashboard.js';
|
||||
import database from './database.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import eventlog from './eventlog.js';
|
||||
import mailer from './mailer.js';
|
||||
import safe from 'safetydance';
|
||||
import users from './users.js';
|
||||
|
||||
const debug = debugModule('box:notifications');
|
||||
const { log, trace } = logger('notifications');
|
||||
|
||||
const TYPE_CLOUDRON_INSTALLED = 'cloudronInstalled';
|
||||
const TYPE_CLOUDRON_UPDATED = 'cloudronUpdated';
|
||||
@@ -44,7 +44,7 @@ async function add(type, title, message, data) {
|
||||
assert.strictEqual(typeof message, 'string');
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
debug(`add: ${type} ${title}`);
|
||||
log(`add: ${type} ${title}`);
|
||||
|
||||
const query = 'INSERT INTO notifications (type, title, message, acknowledged, eventId, context) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
const args = [ type, title, message, false, data?.eventId || null, data.context || '' ];
|
||||
@@ -147,7 +147,7 @@ async function oomEvent(eventId, containerId, app, addonName, event) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_APP_OOM)) {
|
||||
await safe(mailer.oomEvent(admin.email, containerId, app, addonName, event), { debug });
|
||||
await safe(mailer.oomEvent(admin.email, containerId, app, addonName, event), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ async function appUp(eventId, app) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_APP_UP)) {
|
||||
await safe(mailer.appUp(admin.email, app), { debug });
|
||||
await safe(mailer.appUp(admin.email, app), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ async function appDown(eventId, app) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_APP_DOWN)) {
|
||||
await safe(mailer.appDown(admin.email, app), { debug });
|
||||
await safe(mailer.appDown(admin.email, app), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ async function boxUpdateError(eventId, errorMessage) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_CLOUDRON_UPDATE_FAILED)) {
|
||||
await safe(mailer.boxUpdateError(admin.email, errorMessage), { debug });
|
||||
await safe(mailer.boxUpdateError(admin.email, errorMessage), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ async function certificateRenewalError(eventId, fqdn, errorMessage) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_CERTIFICATE_RENEWAL_FAILED)) {
|
||||
await safe(mailer.certificateRenewalError(admin.email, fqdn, errorMessage), { debug });
|
||||
await safe(mailer.certificateRenewalError(admin.email, fqdn, errorMessage), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,7 @@ async function backupFailed(eventId, taskId, errorMessage) {
|
||||
const superadmins = await users.getSuperadmins();
|
||||
for (const superadmin of superadmins) {
|
||||
if (superadmin.notificationConfig.includes(TYPE_BACKUP_FAILED)) {
|
||||
await safe(mailer.backupFailed(superadmin.email, errorMessage, `https://${dashboardFqdn}/logs.html?taskId=${taskId}`), { debug });
|
||||
await safe(mailer.backupFailed(superadmin.email, errorMessage, `https://${dashboardFqdn}/logs.html?taskId=${taskId}`), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ async function rebootRequired() {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_REBOOT)) {
|
||||
await safe(mailer.rebootRequired(admin.email), { debug });
|
||||
await safe(mailer.rebootRequired(admin.email), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ async function lowDiskSpace(message) {
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_DISK_SPACE)) {
|
||||
await safe(mailer.lowDiskSpace(admin.email, message), { debug });
|
||||
await safe(mailer.lowDiskSpace(admin.email, message), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user