console-log-capture
v1.0.3
Published
A library for capturing console logs
Downloads
6
Maintainers
Readme
console-log-capture
A library for capturing console logs
Installation
npm install console-log-capture
Usage
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));
Options
import ConsoleLogCapture from 'console-log-capture';
const consoleLogCapture = new ConsoleLogCapture({
fileName: 'my-logs.txt',
location: './logs/'
});
consoleLogCapture.start();