@allnulled/console-hooker
v1.0.0
Published
Hook console.log seamlessly.
Readme
console-hooker
Hook console.log seamlessly. Node.js or browser.
Installation
npm i -s @allnulled/console-hookerImportation
In node.js:
require("@allnulled/console-hooker");In html:
<script src="node_modules/@allnulled/console-hooker/console-hooker.js"></script>Usage
Once loaded the file, ConsoleHooker is available globally:
const {restore, original} = ConsoleHooker(function(...args) {
original(args);
const list = Array.from(args);
require("fs").appendFileSync("log.txt", JSON.stringify(list) + "\n", "utf8");
});
console.log("hi!"); // log.txt contains now ["hi!"]
console.log("hi!"); // log.txt contains now ["hi!"]\n["hi!"]
console.log("hi!"); // log.txt contains now ["hi!"]\n["hi!"]\n["hi!"]
restore();
console.log("this is not appended");