logger/test/test.cjs

54 lines
1.5 KiB
JavaScript
Raw Permalink 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);
2023-04-13 18:38:48 +02:00
// process.exit();
2023-04-12 20:34:40 +02:00
logger.info('Test');
2023-06-15 12:13:46 +02:00
const spawn = (child) =>
{
return new Promise((resolve) =>
{
2023-04-12 20:34:40 +02:00
child.once('spawn', resolve);
});
};
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ChildProcess = require('node:child_process');
2023-06-15 12:13:46 +02:00
const main = async () =>
{
2023-04-12 20:34:40 +02:00
const child = ChildProcess.fork('./test/otherProcess.js');
logger.attach(child);
await spawn(child);
2023-06-15 12:13:46 +02:00
for (let i = 0; i < 10; i++)
{
2023-04-12 20:34:40 +02:00
await new Promise((resolve) => setTimeout(resolve, 1000));
logger.info(`Iteration ${i}`);
}
};
main();