Files
projects/Dockers/xtream-ppv-bundler/src/logger.js
T
Bram 91f22b54b4
Build and Push Docker Images / build-and-push (push) Successful in 36s
xtream bundler
2026-11-06 19:24:39 +01:00

34 lines
1.0 KiB
JavaScript

'use strict';
const { settings } = require('./settings');
const LEVELS = { error: 0, warn: 1, info: 2, debug: 3 };
function redact(value) {
let text = typeof value === 'string' ? value : String(value);
if (settings.xtreamPassword) {
text = text.split(settings.xtreamPassword).join('***');
}
if (settings.xtreamUsername && settings.xtreamUsername.length >= 4) {
text = text.split(settings.xtreamUsername).join('***');
}
text = text.replace(/([?&](?:username|password)=)[^&\s]+/gi, '$1***');
text = text.replace(/(\/live\/)[^/\s]+\/[^/\s]+/gi, '$1***/***');
return text;
}
function emit(level, args) {
if ((LEVELS[level] ?? 2) > (LEVELS[settings.logLevel] ?? 2)) return;
const line = args.map(redact).join(' ');
const stamp = new Date().toISOString();
process.stdout.write(`${stamp} [${level.toUpperCase()}] ${line}\n`);
}
module.exports = {
debug: (...args) => emit('debug', args),
info: (...args) => emit('info', args),
warn: (...args) => emit('warn', args),
error: (...args) => emit('error', args),
redact,
};