logger/test/test.cjs

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-04-12 20:34:40 +02:00
// eslint-disable-next-line @typescript-eslint/no-var-requires
2023-04-13 15:25:49 +02:00
const { MasterLogger, LogLevel, addLogLevel } = require('../build/cjs');
console.log(LogLevel.debug === LogLevel[0], LogLevel.debug === LogLevel[LogLevel[0]], LogLevel[0]);
// LogLevel[LogLevel.access = 6] = 'access';
addLogLevel('access', 6);
console.log(LogLevel);
2023-04-12 20:34:40 +02:00
const logger = new MasterLogger({
debug: true,
customTypes: [ 'access' ],
customStreams: [ 'access' ],
customTypeMapping: { access: 'access', warn: 'error' },
2023-04-13 15:25:49 +02:00
customColours: {
2023-04-12 20:34:40 +02:00
access: 'green',
// error: '#FF0000'
},
fileRotationFreq: 0.0001,
logLevelMapping: { access: 2 },
broadcastLevel: 3,
webhook: {
url: 'https://discord.com/api/webhooks/1093874668886294548/uDMRD6g1lmq_2EZynsbKytzWoMM-0N4te0m61r_cv1BsSnDKDxG3fvI6sxSoG5t5b_xn'
}
});
console.log(logger);
2023-04-13 15:25:49 +02:00
logger.setLogLevel(LogLevel.access);
console.log(logger.logLevel);
process.exit();
2023-04-12 20:34:40 +02:00
logger.info('Test');
const spawn = (child) => {
return new Promise((resolve) => {
child.once('spawn', resolve);
});
};
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ChildProcess = require('node:child_process');
const main = async () => {
const child = ChildProcess.fork('./test/otherProcess.js');
logger.attach(child);
await spawn(child);
for (let i = 0; i < 10; i++) {
await new Promise((resolve) => setTimeout(resolve, 1000));
logger.info(`Iteration ${i}`);
}
};
main();