This commit is contained in:
1 parent
d7aea0be65
commit
91f22b54b4
30 files changed
+2475
No files matched your search
@@ -0,0 +1,33 @@
|
||||
'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,
|
||||
};
|
||||
Reference in new issue
Block a user