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,13 +1,13 @@
#!/usr/bin/env node
import debugModule from 'debug';
import logger from './src/logger.js';
import fs from 'node:fs';
import net from 'node:net';
import path from 'node:path';
import paths from './src/paths.js';
import util from 'node:util';
const debug = debugModule('syslog:server');
const { log, trace } = logger('syslog');
let gServer = null;
@@ -37,9 +37,9 @@ function parseRFC5424Message(rawMessage) {
}
async function start() {
debug('==========================================');
debug(' Cloudron Syslog Daemon ');
debug('==========================================');
log('==========================================');
log(' Cloudron Syslog Daemon ');
log('==========================================');
gServer = net.createServer();
@@ -52,8 +52,8 @@ async function start() {
const msg = data.toString('utf8').trim(); // strip any trailing empty new lines. it's unclear why we get it in the first place
for (const line of msg.split('\n')) { // empirically, multiple messages can arrive in a single packet
const info = parseRFC5424Message(line);
if (!info) return debug(`Unable to parse: [${msg}]`);
if (!info.appName) return debug(`Ignore unknown app: [${msg}]`);
if (!info) return log(`Unable to parse: [${msg}]`);
if (!info.appName) return log(`Ignore unknown app: [${msg}]`);
const appLogDir = path.join(paths.LOG_DIR, info.appName);
@@ -61,20 +61,20 @@ async function start() {
fs.mkdirSync(appLogDir, { recursive: true });
fs.appendFileSync(`${appLogDir}/app.log`, `${info.timestamp} ${info.message.trim()}\n`);
} catch (error) {
debug(error);
log(error);
}
}
});
socket.on('error', function (error) {
debug(`socket error: ${error}`);
log(`socket error: ${error}`);
});
});
await fs.promises.rm(paths.SYSLOG_SOCKET_FILE, { force: true });
await util.promisify(gServer.listen.bind(gServer))(paths.SYSLOG_SOCKET_FILE);
debug(`Listening on ${paths.SYSLOG_SOCKET_FILE}`);
log(`Listening on ${paths.SYSLOG_SOCKET_FILE}`);
}
async function stop() {
@@ -87,7 +87,7 @@ async function main() {
await start();
process.on('SIGTERM', async function () {
debug('Received SIGTERM. Shutting down.');
log('Received SIGTERM. Shutting down.');
await stop();
setTimeout(process.exit.bind(process), 1000);
});