logger/test/test.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-11-06 16:21:10 +01:00
/* eslint-disable no-console */
const { MasterLogger } = require('../');
2022-11-08 21:03:35 +01:00
const ChildProcess = require('node:child_process');
2022-11-06 16:21:10 +01:00
2022-11-08 21:03:35 +01:00
const spawn = (child) => {
return new Promise((resolve) => {
child.on('spawn', resolve);
});
};
2022-11-06 16:21:10 +01:00
2022-11-08 21:03:35 +01:00
const main = async () => {
const logger = new MasterLogger({
debug: true,
customTypes: [ 'access' ],
customStreams: [ 'access' ],
customTypeMapping: { access: 'access', warn: 'error' },
customColors: { access: 'green' }
});
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
logger.info('Info test');
logger.status('Status test');
logger.debug('Debug test');
logger.warn('Warn test');
logger.error('Error test');
logger.access('Access test');
for (let i = 0; i < 10; i++) await new Promise((resolve) => setTimeout(resolve, 1000));
};
main();