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

@@ -1,12 +1,12 @@
import assert from 'node:assert';
import cloudron from './cloudron.js';
import debugModule from 'debug';
import logger from './logger.js';
import fs from 'node:fs';
import path from 'node:path';
import paths from './paths.js';
import safe from 'safetydance';
const debug = debugModule('box:translation');
const { log, trace } = logger('translation');
// to be used together with getTranslations() => { translations, fallback }
@@ -45,13 +45,13 @@ function translate(input, assets) {
async function getTranslations() {
const fallbackData = fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, 'en.json'), 'utf8');
if (!fallbackData) debug(`getTranslations: Fallback language en not found. ${safe.error.message}`);
if (!fallbackData) log(`getTranslations: Fallback language en not found. ${safe.error.message}`);
const fallback = safe.JSON.parse(fallbackData) || {};
const lang = await cloudron.getLanguage();
const translationData = safe.fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, `${lang}.json`), 'utf8');
if (!translationData) debug(`getTranslations: Requested language ${lang} not found. ${safe.error.message}`);
if (!translationData) log(`getTranslations: Requested language ${lang} not found. ${safe.error.message}`);
const translations = safe.JSON.parse(translationData) || {};
return { translations, fallback };
@@ -60,7 +60,7 @@ async function getTranslations() {
async function listLanguages() {
const [error, result] = await safe(fs.promises.readdir(paths.TRANSLATIONS_DIR));
if (error) {
debug(`listLanguages: Failed to list translations. %${error.message}`);
log(`listLanguages: Failed to list translations. %${error.message}`);
return [ 'en' ]; // we always return english to avoid dashboard breakage
}