console-hijacker
v1.0.4
Published
overwrite console functionality (log, warn, error, and info)
Downloads
1
Readme
console-hijacker
Installation
npm install console-hijacker
Use Case
whenever you call console.log() it always run the consoleHijacker.Log function
- Ctrate a new file YOUR_FILENAME.js
- add the given code
- import in your root file only one time and use every where
FOR .JS
const { default: consoleHijacker } = require('console-hijacker')
consoleHijacker({
Log: (data) => {
// function call when console.log() trigger
},
Warn: (data) => {
// function call when console.warn() trigger
},
Info: (data) => {
// function call when console.info() trigger
},
Error: (data) => {
// function call when console.error() trigger
},
});
FOR TS
import consoleHijacker, { ConsoleType } from "console-hijacker";
consoleHijacker({
Log: function (data: ConsoleType): void {
// function call when console.log() trigger
},
Warn: function (data: ConsoleType): void {
// function call when console.warn() trigger
},
Info: function (data: ConsoleType): void {
// function call when console.info() trigger
},
Error: function (data: ConsoleType): void {
// function call when console.error() trigger
}
})
NOTE: Don't Use console.log(), console.warn(), console.info(), and/or console.error() inside the consoleHijacker function.
WHY NOT: if you use any of these console(s) inside this consoleHijacker function then it run as a loop and through an error of call stack overflow.