logger/test/test.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-11-06 16:21:10 +01:00
/* eslint-disable no-console */
2023-04-12 19:13:14 +02:00
// const { MasterLogger } = require('../build');
// const ChildProcess = require('node:child_process');
2023-06-15 12:13:46 +02:00
import { MasterLogger } from '../build/esm/index.js';
import ChildProcess from 'node:child_process';
2022-11-06 16:21:10 +01:00
2023-06-15 12:13:46 +02:00
const spawn = (child) =>
{
return new Promise((resolve) =>
{
2022-11-08 21:03:35 +01:00
child.on('spawn', resolve);
});
};
2022-11-06 16:21:10 +01:00
2023-06-15 12:13:46 +02:00
const main = async () =>
{
2022-11-08 21:03:35 +01: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: {
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'
}
2022-11-08 21:03:35 +01:00
});
const child = ChildProcess.fork('./test/otherProcess.js');
logger.attach(child);
2022-11-06 16:21:10 +01:00
2022-11-08 21:03:35 +01:00
await spawn(child);
const { types, colours, streamTypes, streamTypeMapping } = logger; // , writeStreams
console.log(types, colours, streamTypes, streamTypeMapping); // , writeStreams
2023-06-15 12:13:46 +02:00
for (let i = 0; i < 10; i++)
{
2023-03-23 17:50:49 +01:00
await new Promise((resolve) => setTimeout(resolve, 1000));
logger.info(`Iteration ${i}`);
}
2022-11-08 21:03:35 +01:00
};
main();