UNPKG

logger-notifier

Version:

Logger Notifier - because sometimes even your code needs a little nudge to get noticed! This npm package makes logging messages to the console more exciting by also sending notifications. Debugging has never been this much fun!

53 lines (46 loc) 1.17 kB
var isInitialized = false, _console = {}; Notification.requestPermission(); function log(body, title) { title = title || "Notification"; if (!("Notification" in window)) { alert("This browser does not support desktop notification"); } else if (Notification.permission === "granted") { new Notification(title, { body: body }); } else if (Notification.permission !== "denied") { Notification.requestPermission(function (permission) { if (permission === "granted") { new Notification(title, { body: body }); } }); } } function err(body, title) { log(body, title || "Error"); } function originalFnCallDecorator(fn, fnName) { return function () { fn.apply(this, arguments); if (typeof _console[fnName] === "function") { _console[fnName].apply(console, arguments); } }; } function destroy() { isInitialized = false; console.log = _console.log; } function init() { if (isInitialized) { return; } isInitialized = true; _console.log = console.log; console.log = originalFnCallDecorator(log, "log"); } module.exports = { log: log, err: err, init: init, destroy: destroy, };