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:
+10
-10
@@ -6,7 +6,7 @@ import cron from './cron.js';
|
||||
import { CronTime } from 'cron';
|
||||
import crypto from 'node:crypto';
|
||||
import database from './database.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import eventlog from './eventlog.js';
|
||||
import hush from './hush.js';
|
||||
import locks from './locks.js';
|
||||
@@ -18,7 +18,7 @@ import storageFilesystem from './storage/filesystem.js';
|
||||
import storageS3 from './storage/s3.js';
|
||||
import storageGcs from './storage/gcs.js';
|
||||
|
||||
const debug = debugModule('box:backups');
|
||||
const { log, trace } = logger('backups');
|
||||
|
||||
|
||||
// format: rsync or tgz
|
||||
@@ -304,7 +304,7 @@ async function del(backupSite, auditSource) {
|
||||
assert.strictEqual(typeof backupSite, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
await safe(storageApi(backupSite).teardown(backupSite.config), { debug }); // ignore error
|
||||
await safe(storageApi(backupSite).teardown(backupSite.config), { debug: log }); // ignore error
|
||||
|
||||
const queries = [
|
||||
{ query: 'DELETE FROM archives WHERE backupId IN (SELECT id FROM backups WHERE siteId=?)', args: [ backupSite.id ] },
|
||||
@@ -437,12 +437,12 @@ async function setConfig(backupSite, newConfig, auditSource) {
|
||||
newConfig = structuredClone(newConfig); // make a copy
|
||||
storageApi(backupSite).injectPrivateFields(newConfig, oldConfig);
|
||||
|
||||
debug('setConfig: validating new storage configuration');
|
||||
log('setConfig: validating new storage configuration');
|
||||
const sanitizedConfig = await storageApi(backupSite).verifyConfig({ id: backupSite.id, provider: backupSite.provider, config: newConfig });
|
||||
|
||||
await update(backupSite, { config: sanitizedConfig });
|
||||
|
||||
debug('setConfig: setting up new storage configuration');
|
||||
log('setConfig: setting up new storage configuration');
|
||||
await storageApi(backupSite).setup(sanitizedConfig);
|
||||
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_SITE_UPDATE, auditSource, { name: backupSite.name, config: storageApi(backupSite).removePrivateFields(newConfig) });
|
||||
@@ -487,13 +487,13 @@ async function add(data, auditSource) {
|
||||
const id = crypto.randomUUID();
|
||||
if (!safe.fs.mkdirSync(`${paths.BACKUP_INFO_DIR}/${id}`)) throw new BoxError(BoxError.FS_ERROR, `Failed to create info dir: ${safe.error.message}`);
|
||||
|
||||
debug('add: validating new storage configuration');
|
||||
log('add: validating new storage configuration');
|
||||
const sanitizedConfig = await storageApi({ provider }).verifyConfig({id, provider, config });
|
||||
|
||||
await database.query('INSERT INTO backupSites (id, name, provider, configJson, contentsJson, limitsJson, integrityKeyPairJson, retentionJson, schedule, encryptionJson, format, enableForUpdates) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[ id, name, provider, JSON.stringify(sanitizedConfig), JSON.stringify(contents), JSON.stringify(limits), JSON.stringify(integrityKeyPair), JSON.stringify(retention), schedule, JSON.stringify(encryption), format, enableForUpdates ]);
|
||||
|
||||
debug('add: setting up new storage configuration');
|
||||
log('add: setting up new storage configuration');
|
||||
await storageApi({ provider }).setup(sanitizedConfig);
|
||||
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_SITE_ADD, auditSource, { id, name, provider, contents, schedule, format });
|
||||
@@ -504,7 +504,7 @@ async function add(data, auditSource) {
|
||||
async function addDefault(auditSource) {
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
debug('addDefault: adding default backup site');
|
||||
log('addDefault: adding default backup site');
|
||||
const defaultBackupSite = {
|
||||
name: 'Default',
|
||||
provider: 'filesystem',
|
||||
@@ -536,7 +536,7 @@ async function createPseudo(data) {
|
||||
encryption.encryptionPasswordHint = '';
|
||||
}
|
||||
|
||||
debug('add: validating new storage configuration');
|
||||
log('add: validating new storage configuration');
|
||||
const sanitizedConfig = await storageApi({ provider }).verifyConfig({id, provider, config });
|
||||
return { id, format, provider, config: sanitizedConfig, encryption };
|
||||
}
|
||||
@@ -547,7 +547,7 @@ async function reinitAll() {
|
||||
if (!safe.fs.mkdirSync(`${paths.BACKUP_INFO_DIR}/${site.id}`, { recursive: true })) throw new BoxError(BoxError.FS_ERROR, `Failed to create info dir: ${safe.error.message}`);
|
||||
const status = await getStatus(site);
|
||||
if (status.state === 'active') continue;
|
||||
safe(remount(site), { debug }); // background
|
||||
safe(remount(site), { debug: log }); // background
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user