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 BoxError from './boxerror.js';
import constants from './constants.js';
import debugModule from 'debug';
import logger from './logger.js';
import docker from './docker.js';
import fs from 'node:fs';
import net from 'node:net';
@@ -15,7 +15,7 @@ import shellModule from './shell.js';
import superagent from '@cloudron/superagent';
import _ from './underscore.js';
const debug = debugModule('box:metrics');
const { log, trace } = logger('metrics');
const shell = shellModule('metrics');
@@ -163,7 +163,7 @@ async function readSystemMetrics() {
}
async function sendToGraphite() {
// debug('sendStatsToGraphite: collecting stats');
// log('sendStatsToGraphite: collecting stats');
const result = await readSystemMetrics();
@@ -203,7 +203,7 @@ async function sendToGraphite() {
});
client.on('error', (error) => {
debug(`Error sending data to graphite: ${error.message}`);
log(`Error sending data to graphite: ${error.message}`);
resolve();
});
@@ -381,7 +381,7 @@ async function pipeContainerToMap(name, statsMap) {
// we used to poll before instead of a stream. but docker caches metrics internally and rate logic has to handle dups
const statsStream = await docker.getStats(name, { stream: true });
statsStream.on('error', (error) => debug(error));
statsStream.on('error', (error) => log(error));
statsStream.on('data', (data) => {
const stats = JSON.parse(data.toString('utf8'));
const metrics = translateContainerStatsSync(stats);
@@ -478,7 +478,7 @@ async function getStream(options) {
const INTERVAL_MSECS = 1000;
intervalId = setInterval(async () => {
if (options.system) await safe(pipeSystemToMap(statsMap), { debug });
if (options.system) await safe(pipeSystemToMap(statsMap), { debug: log });
const result = {};
const nowSecs = Date.now() / 1000; // to match graphite return value