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

View File

@@ -2,7 +2,7 @@ import apps from './apps.js';
import assert from 'node:assert';
import constants from './constants.js';
import express from 'express';
import debugModule from 'debug';
import logger from './logger.js';
import http from 'node:http';
import { HttpError } from '@cloudron/connect-lastmile';
import middleware from './middleware/index.js';
@@ -13,7 +13,7 @@ import safe from 'safetydance';
import util from 'node:util';
import volumes from './volumes.js';
const debug = debugModule('box:dockerproxy');
const { log, trace } = logger('dockerproxy');
let gHttpServer = null;
@@ -49,7 +49,7 @@ function attachDockerRequest(req, res, next) {
// Force node to send out the headers, this is required for the /container/wait api to make the docker cli proceed
res.write(' ');
dockerResponse.on('error', function (error) { debug('dockerResponse error: %o', error); });
dockerResponse.on('error', function (error) { log('dockerResponse error: %o', error); });
dockerResponse.pipe(res, { end: true });
});
@@ -66,7 +66,7 @@ async function containersCreate(req, res, next) {
const appDataDir = path.join(paths.APPS_DATA_DIR, req.resources.app.id, 'data');
debug('containersCreate: original bind mounts:', req.body.HostConfig.Binds);
log('containersCreate: original bind mounts:', req.body.HostConfig.Binds);
const [error, result] = await safe(volumes.list());
if (error) return next(new HttpError(500, `Error listing volumes: ${error.message}`));
@@ -82,14 +82,14 @@ async function containersCreate(req, res, next) {
const volumeName = bind.match(new RegExp('/media/([^:/]+)/?'))[1];
const volume = volumesByName[volumeName];
if (volume) binds.push(bind.replace(new RegExp(`^/media/${volumeName}`), volume.hostPath));
else debug(`containersCreate: dropped unknown volume ${volumeName}`);
else log(`containersCreate: dropped unknown volume ${volumeName}`);
} else {
req.dockerRequest.abort();
return next(new HttpError(400, 'Binds must be under /app/data/ or /media'));
}
}
debug('containersCreate: rewritten bind mounts:', binds);
log('containersCreate: rewritten bind mounts:', binds);
safe.set(req.body, 'HostConfig.Binds', binds);
const plainBody = JSON.stringify(req.body);
@@ -125,7 +125,7 @@ async function start() {
if (constants.TEST) {
proxyServer.use(function (req, res, next) {
debug('proxying: ' + req.method, req.url);
log('proxying: ' + req.method, req.url);
next();
});
}
@@ -177,7 +177,7 @@ async function start() {
});
});
debug(`start: listening on 172.18.0.1:${constants.DOCKER_PROXY_PORT}`);
log(`start: listening on 172.18.0.1:${constants.DOCKER_PROXY_PORT}`);
await util.promisify(gHttpServer.listen.bind(gHttpServer))(constants.DOCKER_PROXY_PORT, '172.18.0.1');
}