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:
Girish Ramakrishnan
2026-03-12 22:55:28 +05:30
parent d57554a48c
commit 01d0c738bc
104 changed files with 1187 additions and 1174 deletions
+9 -9
View File
@@ -1,22 +1,22 @@
import assert from 'node:assert';
import BoxError from './boxerror.js';
import debugModule from 'debug';
import logger from './logger.js';
import Docker from 'dockerode';
import safe from 'safetydance';
import tokens from './tokens.js';
const debug = debugModule('box:janitor');
const { log, trace } = logger('janitor');
const gConnection = new Docker({ socketPath: '/var/run/docker.sock' });
async function cleanupTokens() {
debug('Cleaning up expired tokens');
log('Cleaning up expired tokens');
const [error, result] = await safe(tokens.delExpired());
if (error) return debug('cleanupTokens: error removing expired tokens. %o', error);
if (error) return log('cleanupTokens: error removing expired tokens. %o', error);
debug(`Cleaned up ${result} expired tokens`);
log(`Cleaned up ${result} expired tokens`);
}
async function cleanupTmpVolume(containerInfo) {
@@ -24,7 +24,7 @@ async function cleanupTmpVolume(containerInfo) {
const cmd = 'find /tmp -type f -mtime +10 -exec rm -rf {} +'.split(' '); // 10 day old files
debug(`cleanupTmpVolume ${JSON.stringify(containerInfo.Names)}`);
log(`cleanupTmpVolume ${JSON.stringify(containerInfo.Names)}`);
const [error, execContainer] = await safe(gConnection.getContainer(containerInfo.Id).exec({ Cmd: cmd, AttachStdout: true, AttachStderr: true, Tty: false }));
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Failed to exec container: ${error.message}`);
@@ -41,16 +41,16 @@ async function cleanupTmpVolume(containerInfo) {
}
async function cleanupDockerVolumes() {
debug('Cleaning up docker volumes');
log('Cleaning up docker volumes');
const [error, containers] = await safe(gConnection.listContainers({ all: 0 }));
if (error) throw new BoxError(BoxError.DOCKER_ERROR, error);
for (const container of containers) {
await safe(cleanupTmpVolume(container), { debug }); // intentionally ignore error
await safe(cleanupTmpVolume(container), { debug: log }); // intentionally ignore error
}
debug('Cleaned up docker volumes');
log('Cleaned up docker volumes');
}
export default {