npm install console-log-capture
import ConsoleLogCapture from 'console-log-capture';
const consoleLogCapture = new ConsoleLogCapture();
consoleLogCapture.start();
console.log('Hello World!');
console.log('Hello World! Again!');
console.log('Hello World! Again! Again!');
console.log('Hello World! Again! Again! Again!');
// get all logs
console.log(consoleLogCapture.getCapturedLogs());
consoleLogCapture.stop();
// with date range
const timeFormat = new Date();
const start = "2023-6-30-3:00"; // date format: yyyy-mm-dd-hh:mm
const end = timeFormat.getFullYear() + '-' + (timeFormat.getMonth() + 1) + '-' + timeFormat.getDate() + '-' + timeFormat.getHours() + ':' + timeFormat.getMinutes();
console.log(consoleLogCapture.getCapturedLogs(start, end));
import ConsoleLogCapture from 'console-log-capture';
const consoleLogCapture = new ConsoleLogCapture({
fileName: 'my-logs.txt',
location: './logs/'
});
consoleLogCapture.start();