Skip to content

appujet/console-log-capture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

console-log-capture

A library for capturing console logs

Build Status Coverage Status npm version License: MIT

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();