34 lines
1.0 KiB
JavaScript
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,
|
|
};
|