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:
+17
-17
@@ -9,7 +9,7 @@ import backuptask from './backuptask.js';
|
||||
import BoxError from './boxerror.js';
|
||||
import community from './community.js';
|
||||
import constants from './constants.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import df from './df.js';
|
||||
import dns from './dns.js';
|
||||
import docker from './docker.js';
|
||||
@@ -28,7 +28,7 @@ import services from './services.js';
|
||||
import shellModule from './shell.js';
|
||||
import _ from './underscore.js';
|
||||
|
||||
const debug = debugModule('box:apptask');
|
||||
const { log, trace } = logger('apptask');
|
||||
const shell = shellModule('apptask');
|
||||
|
||||
const LOGROTATE_CONFIG_EJS = fs.readFileSync(import.meta.dirname + '/logrotate.ejs', { encoding: 'utf8' }),
|
||||
@@ -63,7 +63,7 @@ async function allocateContainerIp(app) {
|
||||
|
||||
if (app.manifest.id === constants.PROXY_APP_APPSTORE_ID) return;
|
||||
|
||||
await promiseRetry({ times: 10, interval: 0, debug }, async function () {
|
||||
await promiseRetry({ times: 10, interval: 0, debug: log }, async function () {
|
||||
const iprange = iputils.intFromIp(constants.APPS_IPv4_END) - iputils.intFromIp(constants.APPS_IPv4_START);
|
||||
const rnd = Math.floor(Math.random() * iprange);
|
||||
const containerIp = iputils.ipFromInt(iputils.intFromIp(constants.APPS_IPv4_START) + rnd);
|
||||
@@ -92,7 +92,7 @@ async function deleteAppDir(app, options) {
|
||||
|
||||
const resolvedAppDataDir = stat.isSymbolicLink() ? safe.fs.readlinkSync(appDataDir) : appDataDir;
|
||||
|
||||
debug(`deleteAppDir - removing files in ${resolvedAppDataDir}`);
|
||||
log(`deleteAppDir - removing files in ${resolvedAppDataDir}`);
|
||||
|
||||
if (safe.fs.existsSync(resolvedAppDataDir)) {
|
||||
const entries = safe.fs.readdirSync(resolvedAppDataDir);
|
||||
@@ -105,7 +105,7 @@ async function deleteAppDir(app, options) {
|
||||
const entryStat = safe.fs.statSync(fullPath);
|
||||
if (entryStat && !entryStat.isDirectory()) {
|
||||
safe.fs.unlinkSync(fullPath);
|
||||
debug(`deleteAppDir - ${fullPath} ${safe.error?.message || ''}`);
|
||||
log(`deleteAppDir - ${fullPath} ${safe.error?.message || ''}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ async function deleteContainers(app, options) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
|
||||
debug('deleteContainer: deleting app containers (app, scheduler)');
|
||||
log('deleteContainer: deleting app containers (app, scheduler)');
|
||||
|
||||
// remove configs that rely on container id
|
||||
await removeLogrotateConfig(app);
|
||||
@@ -149,7 +149,7 @@ async function cleanupLogs(app) {
|
||||
|
||||
// note that redis container logs are cleaned up by the addon
|
||||
const [error] = await safe(fs.promises.rm(path.join(paths.LOG_DIR, app.id), { force: true, recursive: true }));
|
||||
if (error) debug('cleanupLogs: cannot cleanup logs: %o', error);
|
||||
if (error) log('cleanupLogs: cannot cleanup logs: %o', error);
|
||||
}
|
||||
|
||||
async function verifyManifest(manifest) {
|
||||
@@ -167,10 +167,10 @@ async function downloadIcon(app) {
|
||||
|
||||
let packageIcon = null;
|
||||
if (app.versionsUrl && app.manifest.iconUrl) {
|
||||
debug(`downloadIcon: Downloading community icon ${app.manifest.iconUrl}`);
|
||||
log(`downloadIcon: Downloading community icon ${app.manifest.iconUrl}`);
|
||||
packageIcon = await community.downloadIcon(app.manifest);
|
||||
} else if (app.appStoreId) {
|
||||
debug(`downloadIcon: Downloading icon of ${app.appStoreId}@${app.manifest.version}`);
|
||||
log(`downloadIcon: Downloading icon of ${app.appStoreId}@${app.manifest.version}`);
|
||||
packageIcon = await appstore.downloadIcon(app.appStoreId, app.manifest.version);
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ async function updateChecklist(app, newChecks, acknowledged = false) {
|
||||
}
|
||||
|
||||
async function startApp(app) {
|
||||
debug('startApp: starting container');
|
||||
log('startApp: starting container');
|
||||
|
||||
if (app.runState === apps.RSTATE_STOPPED) return;
|
||||
|
||||
@@ -378,7 +378,7 @@ async function createContainer(app) {
|
||||
|
||||
if (app.manifest.id === constants.PROXY_APP_APPSTORE_ID) return;
|
||||
|
||||
debug('createContainer: creating container');
|
||||
log('createContainer: creating container');
|
||||
|
||||
const container = await docker.createContainer(app);
|
||||
|
||||
@@ -808,7 +808,7 @@ async function run(appId, args, progressCallback) {
|
||||
|
||||
const app = await apps.get(appId);
|
||||
|
||||
debug(`run: startTask installationState: ${app.installationState} runState: ${app.runState}`);
|
||||
log(`run: startTask installationState: ${app.installationState} runState: ${app.runState}`);
|
||||
|
||||
let cmd;
|
||||
|
||||
@@ -855,19 +855,19 @@ async function run(appId, args, progressCallback) {
|
||||
cmd = updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null });
|
||||
break;
|
||||
default:
|
||||
debug('run: apptask launched with invalid command');
|
||||
log('run: apptask launched with invalid command');
|
||||
throw new BoxError(BoxError.INTERNAL_ERROR, 'Unknown install command in apptask:' + app.installationState);
|
||||
}
|
||||
|
||||
const [error, result] = await safe(cmd); // only some commands like backup return a result
|
||||
if (error) {
|
||||
debug(`run: app error for state ${app.installationState}: %o`, error);
|
||||
log(`run: app error for state ${app.installationState}: %o`, error);
|
||||
|
||||
if (app.installationState === apps.ISTATE_PENDING_UPDATE && error.backupError) {
|
||||
debug('run: update aborted because backup failed');
|
||||
await safe(updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }, { debug }));
|
||||
log('run: update aborted because backup failed');
|
||||
await safe(updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }, { debug: log }));
|
||||
} else {
|
||||
await safe(updateApp(app, { installationState: apps.ISTATE_ERROR, error: makeTaskError(error, app) }), { debug });
|
||||
await safe(updateApp(app, { installationState: apps.ISTATE_ERROR, error: makeTaskError(error, app) }), { debug: log });
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user