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
+3 -3
View File
@@ -1,13 +1,13 @@
import apps from '../apps.js';
import assert from 'node:assert';
import BoxError from '../boxerror.js';
import debugModule from 'debug';
import logger from '../logger.js';
import { HttpError } from '@cloudron/connect-lastmile';
import safe from 'safetydance';
import tokens from '../tokens.js';
import users from '../users.js';
const debug = debugModule('box:routes/accesscontrol');
const { log, trace } = logger('routes/accesscontrol');
async function passwordAuth(req, res, next) {
@@ -55,7 +55,7 @@ async function tokenAuth(req, res, next) {
const user = await users.get(token.identifier);
if (!user) return next(new HttpError(401, 'User not found'));
if (!user.active) {
debug(`tokenAuth: ${user.username || user.id} is not active`);
log(`tokenAuth: ${user.username || user.id} is not active`);
return next(new HttpError(401, 'User not active'));
}
+4 -4
View File
@@ -8,7 +8,7 @@ import backupSites from '../backupsites.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 { HttpError } from '@cloudron/connect-lastmile';
import { HttpSuccess } from '@cloudron/connect-lastmile';
import metrics from '../metrics.js';
@@ -18,7 +18,7 @@ import users from '../users.js';
import { getImageContentType } from '../image-content-type.js';
import WebSocket from 'ws';
const debug = debugModule('box:routes/apps');
const { log, trace } = logger('routes/apps');
async function load(req, res, next) {
@@ -829,7 +829,7 @@ async function startExecWebSocket(req, res, next) {
duplexStream.on('end', function () { ws.close(); });
duplexStream.on('close', function () { ws.close(); });
duplexStream.on('error', function (streamError) {
debug('duplexStream error: %o', streamError);
log('duplexStream error: %o', streamError);
});
duplexStream.on('data', function (data) {
if (ws.readyState !== WebSocket.OPEN) return;
@@ -837,7 +837,7 @@ async function startExecWebSocket(req, res, next) {
});
ws.on('error', function (wsError) {
debug('websocket error: %o', wsError);
log('websocket error: %o', wsError);
});
ws.on('message', function (msg) {
duplexStream.write(msg);
+3 -3
View File
@@ -2,7 +2,7 @@ import assert from 'node:assert';
import AuditSource from '../auditsource.js';
import BoxError from '../boxerror.js';
import constants from '../constants.js';
import debugModule from 'debug';
import logger from '../logger.js';
import eventlog from '../eventlog.js';
import { HttpError } from '@cloudron/connect-lastmile';
import { HttpSuccess } from '@cloudron/connect-lastmile';
@@ -12,7 +12,7 @@ import speakeasy from 'speakeasy';
import tokens from '../tokens.js';
import users from '../users.js';
const debug = debugModule('box:routes/cloudron');
const { log, trace } = logger('routes/cloudron');
async function login(req, res, next) {
@@ -32,7 +32,7 @@ async function login(req, res, next) {
const auditSource = AuditSource.fromRequest(req);
await eventlog.add(req.user.ghost ? eventlog.ACTION_USER_LOGIN_GHOST : eventlog.ACTION_USER_LOGIN, auditSource, { userId: req.user.id, user: users.removePrivateFields(req.user), type, appId: oidcClients.ID_CLI });
await safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource), { debug });
await safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource), { debug: log });
next(new HttpSuccess(200, token));
}
+3 -3
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert';
import AuditSource from '../auditsource.js';
import BoxError from '../boxerror.js';
import debugModule from 'debug';
import logger from '../logger.js';
import http from 'node:http';
import { HttpError } from '@cloudron/connect-lastmile';
import { HttpSuccess } from '@cloudron/connect-lastmile';
@@ -9,7 +9,7 @@ import mailServer from '../mailserver.js';
import safe from 'safetydance';
import services from '../services.js';
const debug = debugModule('box:routes/mailserver');
const { log, trace } = logger('routes/mailserver');
async function proxyToMailContainer(port, pathname, req, res, next) {
@@ -61,7 +61,7 @@ async function proxyAndRestart(req, res, next) {
if (httpError) return next(httpError);
// for success, the proxy already sent the response. do not proceed to connect-lastmile which will result in double headers
await safe(mailServer.restart(), { debug });
await safe(mailServer.restart(), { debug: log });
});
}
+13 -13
View File
@@ -1,7 +1,7 @@
import apps from '../../apps.js';
import appstore from '../../appstore.js';
import backupSites from '../../backupsites.js';
import debugModule from 'debug';
import logger from '../../logger.js';
import constants from '../../constants.js';
import database from '../../database.js';
import assert from 'node:assert/strict';
@@ -16,7 +16,7 @@ import tasks from '../../tasks.js';
import timers from 'timers/promises';
import tokens from '../../tokens.js';
const debug = debugModule('box:test/common');
const { log, trace } = logger('test/common');
const manifest = {
'id': 'io.cloudron.test',
@@ -98,17 +98,17 @@ const serverUrl = `http://localhost:${constants.PORT}`;
async function setupServer() {
debug('Setting up server');
log('Setting up server');
await database.initialize();
await database._clear();
await appstore._setApiServerOrigin(mockApiServerOrigin);
await oidcServer.stop();
await server.start();
debug('Set up server complete');
log('Set up server complete');
}
async function setup() {
debug('Setting up');
log('Setting up');
await setupServer();
@@ -165,15 +165,15 @@ async function setup() {
await settings._set(settings.APPSTORE_API_TOKEN_KEY, appstoreToken); // appstore token
debug('Setup complete');
log('Setup complete');
}
async function cleanup() {
debug('Cleaning up');
log('Cleaning up');
await server.stop();
await oidcServer.stop();
if (!nock.isActive()) nock.activate();
debug('Cleaned up');
log('Cleaned up');
}
function clearMailQueue() {
@@ -187,7 +187,7 @@ async function checkMails(number) {
}
async function waitForTask(taskId) {
debug(`Waiting for task: ${taskId}`);
log(`Waiting for task: ${taskId}`);
for (let i = 0; i < 30; i++) {
const result = await tasks.get(taskId);
@@ -197,7 +197,7 @@ async function waitForTask(taskId) {
throw new Error(`Task ${taskId} failed: ${result.error.message} - ${result.error.stack}`);
}
await timers.setTimeout(2000);
debug(`Waiting for task to ${taskId} finish`);
log(`Waiting for task to ${taskId} finish`);
}
throw new Error(`Task ${taskId} never finished`);
}
@@ -206,16 +206,16 @@ async function waitForAsyncTask(es) {
return new Promise((resolve, reject) => {
const messages = [];
es.addEventListener('message', function (message) {
debug(`waitForAsyncTask: ${message.data}`);
log(`waitForAsyncTask: ${message.data}`);
messages.push(JSON.parse(message.data));
if (messages[messages.length-1].type === 'done') {
debug('waitForAsyncTask: finished');
log('waitForAsyncTask: finished');
es.close();
resolve(messages);
}
});
es.addEventListener('error', function (error) {
debug('waitForAsyncTask: errored', error);
log('waitForAsyncTask: errored', error);
es.close();
const e = new Error(error.message);
e.code = error.code;