@justeat/f-logger
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -7,2 +7,17 @@ # Changelog | ||
v0.4.0 | ||
------------------------------ | ||
*March 19, 2018* | ||
### Added | ||
- JS unit tests for `Logger.js` and `ErrorLogger.js` (there are still some more to add). | ||
### Changed | ||
- Update `gulp-build-fozzie` to v7.13.0. | ||
- Moved `errorLoggerConfig` object into `errorLogger`'s config property`. | ||
### Removed | ||
- `ConsoleLogger.js`. Absorbed into `Logger.js`'s `output` function. | ||
v0.3.0 | ||
@@ -9,0 +24,0 @@ ------------------------------ |
@@ -7,5 +7,4 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
*/ | ||
var consoleLogger = require('./modules/ConsoleLogger'); | ||
var logger = require('./modules/Logger'); | ||
var errorLogger = require('./modules/ErrorLogger'); | ||
var LoggerObject = require('./modules/Logger'); | ||
var ErrorLoggerObject = require('./modules/ErrorLogger'); | ||
/** | ||
@@ -19,5 +18,4 @@ * Set the debugmode flag | ||
*/ | ||
var consoleLog = new consoleLogger.ConsoleLogger(); | ||
var loggerLog = new logger.Logger({ debugMode: debugMode, consoleLog: consoleLog }); | ||
var errorLog = new errorLogger.ErrorLogger({ debugMode: debugMode, logger: loggerLog }); | ||
var logger = new LoggerObject({ debugMode: debugMode }); | ||
var errorLogger = new ErrorLoggerObject({ logger: logger }); | ||
@@ -29,3 +27,3 @@ /** | ||
var log = function log(message) { | ||
loggerLog.log(message); | ||
logger.log(message); | ||
}; | ||
@@ -38,5 +36,9 @@ | ||
var logError = function logError(message) { | ||
errorLog.log(message); | ||
errorLogger.log(message, 'Error'); | ||
}; | ||
var logWarning = function logWarning(message) { | ||
errorLogger.log(message, 'Warn'); | ||
}; | ||
/** | ||
@@ -46,3 +48,3 @@ * Output the log history from local storage to console | ||
var getHistory = function getHistory() { | ||
loggerLog.getPersistentData(); | ||
logger.getPersistentData(); | ||
}; | ||
@@ -54,3 +56,3 @@ | ||
var clearHistory = function clearHistory() { | ||
loggerLog.clearPersistentData(); | ||
logger.clearPersistentData(); | ||
}; | ||
@@ -63,4 +65,4 @@ | ||
debugMode = true; | ||
loggerLog = new logger.Logger({ debugMode: debugMode, consoleLog: consoleLog }); | ||
errorLog = new errorLogger.ErrorLogger({ debugMode: debugMode, logger: loggerLog }); | ||
logger = new LoggerObject({ debugMode: debugMode }); | ||
errorLogger = new ErrorLoggerObject({ logger: logger }); | ||
}; | ||
@@ -73,4 +75,4 @@ | ||
debugMode = false; | ||
loggerLog = new logger.Logger({ debugMode: debugMode, consoleLog: consoleLog }); | ||
errorLog = new errorLogger.ErrorLogger({ debugMode: debugMode, logger: loggerLog }); | ||
logger = new LoggerObject({ debugMode: debugMode }); | ||
errorLogger = new ErrorLoggerObject({ logger: logger }); | ||
}; | ||
@@ -82,3 +84,3 @@ | ||
var errorLogInit = function errorLogInit(config) { | ||
errorLog.init(config); | ||
errorLogger.init(config); | ||
}; | ||
@@ -98,2 +100,3 @@ | ||
log: log, | ||
logWarning: logWarning, | ||
logError: logError, | ||
@@ -108,71 +111,8 @@ errorLogInit: errorLogInit, | ||
},{"./modules/ConsoleLogger":2,"./modules/ErrorLogger":3,"./modules/Logger":4}],2:[function(require,module,exports){ | ||
},{"./modules/ErrorLogger":2,"./modules/Logger":3}],2:[function(require,module,exports){ | ||
'use strict'; | ||
/** | ||
* Create the ConsoleLogger constructor | ||
* @constructor | ||
* @param {function} inject the innerText fix | ||
*/ | ||
function ConsoleLogger(innerText) { | ||
this.innerText = innerText; | ||
this.ieFix(); | ||
} | ||
/** | ||
* Wrap console.log in case we want to extend the logger output | ||
*/ | ||
ConsoleLogger.prototype.log = function log(message) { | ||
window.console.log(message); | ||
}; | ||
/** | ||
* Some versions of IE will error when console.log is called and dev tools is closed | ||
*/ | ||
ConsoleLogger.prototype.ieFix = function ieFix() { | ||
var innerTextDependency = this.innerText; | ||
window.console = window.console || { | ||
log: function log(consoleMessage) { | ||
var messageDiv = void 0; | ||
var messageP = void 0; | ||
if (document.readyState === 'completed') { | ||
if (document.getElementById('JsMessageDiv')) { | ||
messageDiv = document.getElementById('JsMessageDiv'); | ||
} else { | ||
messageDiv = document.createElement('div'); | ||
messageDiv.id = 'JsMessageDiv'; | ||
document.getElementsByTagName('body')[0].appendChild(messageDiv); | ||
} | ||
messageP = document.createElement('p'); | ||
innerTextDependency.set(messageP, consoleMessage); | ||
messageDiv.appendChild(messageP); | ||
} | ||
} | ||
}; | ||
}; | ||
/** | ||
* Export ConsoleLogger | ||
*/ | ||
module.exports = { | ||
ConsoleLogger: ConsoleLogger | ||
}; | ||
},{}],3:[function(require,module,exports){ | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/* global ActiveXObject */ | ||
/** | ||
* Create the default ErrorLogger config object | ||
*/ | ||
var errorLoggerConfig = { | ||
serverFileUrl: '/javascript/shared/js-error.js', | ||
loggerCallback: null, | ||
winlogCallback: null | ||
}; | ||
@@ -189,4 +129,7 @@ /** | ||
this.config = config; | ||
this.debugMode = this.config.debugMode; | ||
this.logger = this.config.logger; | ||
this.logger = config.logger; | ||
this.debugMode = config.logger.debugMode; | ||
this.config.serverFileUrl = config.serverFileUrl || '/js/shared/js-error.js'; | ||
this.config.loggerCallback = config.loggerCallback || null; | ||
this.config.winlogCallback = config.winlogCallback || null; | ||
this.bindOnError(); | ||
@@ -210,7 +153,7 @@ } | ||
if (typeof errorLoggerConfig.loggerCallback === 'function') { | ||
if (typeof this.config.loggerCallback === 'function') { | ||
if (errorLevel === 'Error') { | ||
errorLoggerConfig.winlogCallback.call(this, errorString, pageUrl, lineNumber); | ||
this.config.winlogCallback.call(this, errorString, pageUrl, lineNumber); | ||
} else { | ||
errorLoggerConfig.loggerCallback.call(this, errorString, pageUrl); | ||
this.config.loggerCallback.call(this, errorString, pageUrl); | ||
} | ||
@@ -229,5 +172,5 @@ } | ||
ErrorLogger.prototype.init = function init(config) { | ||
errorLoggerConfig.serverFileUrl = config.serverFileUrl || errorLoggerConfig.serverFileUrl; | ||
errorLoggerConfig.loggerCallback = config.loggerCallback || errorLoggerConfig.loggerCallback; | ||
errorLoggerConfig.winlogCallback = config.winlogCallback || errorLoggerConfig.winlogCallback; | ||
this.config.serverFileUrl = config.serverFileUrl || this.config.serverFileUrl; | ||
this.config.loggerCallback = config.loggerCallback || this.config.loggerCallback; | ||
this.config.winlogCallback = config.winlogCallback || this.config.winlogCallback; | ||
}; | ||
@@ -249,4 +192,3 @@ | ||
var requestUrl = errorLoggerConfig.serverFile + '?error=' + encodeURIComponent(dataString); | ||
var requestUrl = this.config.serverFileUrl + '?error=' + encodeURIComponent(dataString); | ||
if (window.XMLHttpRequest) { | ||
@@ -265,3 +207,3 @@ httpRequest = new XMLHttpRequest(); | ||
/** | ||
* Bind ErrorLogger to windows.onerror | ||
* Bind ErrorLogger to window.onerror | ||
*/ | ||
@@ -281,7 +223,5 @@ ErrorLogger.prototype.bindOnError = function bindOnError() { | ||
*/ | ||
module.exports = { | ||
ErrorLogger: ErrorLogger | ||
}; | ||
module.exports = ErrorLogger; | ||
},{}],4:[function(require,module,exports){ | ||
},{}],3:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -296,3 +236,2 @@ | ||
* @param {bool} config.debugMode - sets debugMode to toggle console messages on/off | ||
* @param {object} config.consoleLog - instance of ConsoleLogger object | ||
*/ | ||
@@ -302,3 +241,2 @@ function Logger(config) { | ||
this.debugMode = this.config.debugMode; | ||
this.consoleLog = this.config.consoleLog; | ||
this.data = {}; | ||
@@ -378,3 +316,5 @@ } | ||
Logger.prototype.output = function output(message) { | ||
this.consoleLog.log(message); | ||
if (typeof window.console !== 'undefined') { | ||
window.console.log(message); | ||
} | ||
}; | ||
@@ -394,7 +334,5 @@ | ||
*/ | ||
module.exports = { | ||
Logger: Logger | ||
}; | ||
module.exports = Logger; | ||
},{}]},{},[1]) | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function o(e,t,r){function n(l,g){if(!t[l]){if(!e[l]){var a="function"==typeof require&&require;if(!g&&a)return a(l,!0);if(i)return i(l,!0);var c=new Error("Cannot find module '"+l+"'");throw c.code="MODULE_NOT_FOUND",c}var s=t[l]={"exports":{}};e[l][0].call(s.exports,function(o){var t=e[l][1][o];return n(t||o)},s,s.exports,o,e,t,r)}return t[l].exports}for(var i="function"==typeof require&&require,l=0;l<r.length;l++)n(r[l]);return n}({"1":[function(o,e,t){"use strict";var r=o("./modules/ConsoleLogger"),n=o("./modules/Logger"),i=o("./modules/ErrorLogger"),l=!1,g=new r.ConsoleLogger,a=new n.Logger({"debugMode":l,"consoleLog":g}),c=new i.ErrorLogger({"debugMode":l,"logger":a});e.exports={"log":function(o){a.log(o)},"logError":function(o){c.log(o)},"errorLogInit":function(o){c.init(o)},"getHistory":function(){a.getPersistentData()},"clearHistory":function(){a.clearPersistentData()},"enableDebugMode":function(){l=!0,a=new n.Logger({"debugMode":l,"consoleLog":g}),c=new i.ErrorLogger({"debugMode":l,"logger":a})},"disableDebugMode":function(){l=!1,a=new n.Logger({"debugMode":l,"consoleLog":g}),c=new i.ErrorLogger({"debugMode":l,"logger":a})},"getDebugMode":function(){return l}}},{"./modules/ConsoleLogger":2,"./modules/ErrorLogger":3,"./modules/Logger":4}],"2":[function(o,e,t){"use strict";function r(o){this.innerText=o,this.ieFix()}r.prototype.log=function(o){window.console.log(o)},r.prototype.ieFix=function(){var o=this.innerText;window.console=window.console||{"log":function(e){var t=void 0,r=void 0;"completed"===document.readyState&&(document.getElementById("JsMessageDiv")?t=document.getElementById("JsMessageDiv"):((t=document.createElement("div")).id="JsMessageDiv",document.getElementsByTagName("body")[0].appendChild(t)),r=document.createElement("p"),o.set(r,e),t.appendChild(r))}}},e.exports={"ConsoleLogger":r}},{}],"3":[function(o,e,t){"use strict";function r(o){this.config=o,this.debugMode=this.config.debugMode,this.logger=this.config.logger,this.bindOnError()}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},i={"serverFileUrl":"/javascript/shared/js-error.js","loggerCallback":null,"winlogCallback":null};r.prototype.log=function(o,e,t){var r=window.location.toString(),n={"pageUrl":r,"Exception":o,"Level":e};this.logger.log(n),this.debugMode||(this.logToServer(n),"function"==typeof i.loggerCallback&&("Error"===e?i.winlogCallback.call(this,o,r,t):i.loggerCallback.call(this,o,r)))},r.prototype.init=function(o){i.serverFileUrl=o.serverFileUrl||i.serverFileUrl,i.loggerCallback=o.loggerCallback||i.loggerCallback,i.winlogCallback=o.winlogCallback||i.winlogCallback},r.prototype.logToServer=function(o){var e=void 0,t="";t="object"===(void 0===o?"undefined":n(o))?JSON.stringify(o):o;var r=i.serverFile+"?error="+encodeURIComponent(t);if(window.XMLHttpRequest)e=new XMLHttpRequest;else{if(!window.ActiveXObject)return;e=new ActiveXObject("Microsoft.XMLHTTP")}e.open("GET",r),e.send()},r.prototype.bindOnError=function(){var o=this;window.onerror=function(e,t,r,n){var i=e+" : "+t+" : Line "+r+" : Char "+n;return o.log(i,"Error",r),!0}},e.exports={"ErrorLogger":r}},{}],"4":[function(o,e,t){"use strict";function r(o){this.config=o,this.debugMode=this.config.debugMode,this.consoleLog=this.config.consoleLog,this.data={}}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o};r.prototype.log=function(o){var e=o;if(this.debugMode){var t=Date.now();if(this.data[t]=e,"object"===("undefined"==typeof localStorage?"undefined":n(localStorage))){try{e=JSON.stringify(e)}catch(o){e="Unable to stringify the incoming message object : "+o.message}try{localStorage.setItem(t,e)}catch(o){this.output("Local storage error: "+o)}}this.output(e)}},r.prototype.getPersistentData=function(){if(localStorage)if(localStorage.length>0){var o=void 0,e=void 0,t=void 0,r=void 0;for(this.output("/***** Output local storage *****/"),o=0;o<localStorage.length;o++)e=Number(localStorage.key(o)),t=localStorage[e],"Invalid Date"!==(r=new Date(e))&&this.output(r+" => "+t);this.output("/***** End of local storage *****/")}else this.output("Local storage is empty");else this.output("Local storage not available")},r.prototype.clearPersistentData=function(){localStorage&&(localStorage.clear(),this.output("Local storage cleared"))},r.prototype.output=function(o){this.consoleLog.log(o)},Date.now||(Date.now=function(){return(new Date).getTime()}),e.exports={"Logger":r}},{}]},{},[1]); | ||
!function o(t,e,r){function n(l,a){if(!e[l]){if(!t[l]){var c="function"==typeof require&&require;if(!a&&c)return c(l,!0);if(i)return i(l,!0);var g=new Error("Cannot find module '"+l+"'");throw g.code="MODULE_NOT_FOUND",g}var s=e[l]={"exports":{}};t[l][0].call(s.exports,function(o){var e=t[l][1][o];return n(e||o)},s,s.exports,o,t,e,r)}return e[l].exports}for(var i="function"==typeof require&&require,l=0;l<r.length;l++)n(r[l]);return n}({"1":[function(o,t,e){"use strict";var r=o("./modules/Logger"),n=o("./modules/ErrorLogger"),i=!1,l=new r({"debugMode":i}),a=new n({"logger":l});t.exports={"log":function(o){l.log(o)},"logWarning":function(o){a.log(o,"Warn")},"logError":function(o){a.log(o,"Error")},"errorLogInit":function(o){a.init(o)},"getHistory":function(){l.getPersistentData()},"clearHistory":function(){l.clearPersistentData()},"enableDebugMode":function(){l=new r({"debugMode":i=!0}),a=new n({"logger":l})},"disableDebugMode":function(){l=new r({"debugMode":i=!1}),a=new n({"logger":l})},"getDebugMode":function(){return i}}},{"./modules/ErrorLogger":2,"./modules/Logger":3}],"2":[function(o,t,e){"use strict";function r(o){this.config=o,this.logger=o.logger,this.debugMode=o.logger.debugMode,this.config.serverFileUrl=o.serverFileUrl||"/js/shared/js-error.js",this.config.loggerCallback=o.loggerCallback||null,this.config.winlogCallback=o.winlogCallback||null,this.bindOnError()}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o};r.prototype.log=function(o,t,e){var r=window.location.toString(),n={"pageUrl":r,"Exception":o,"Level":t};this.logger.log(n),this.debugMode||(this.logToServer(n),"function"==typeof this.config.loggerCallback&&("Error"===t?this.config.winlogCallback.call(this,o,r,e):this.config.loggerCallback.call(this,o,r)))},r.prototype.init=function(o){this.config.serverFileUrl=o.serverFileUrl||this.config.serverFileUrl,this.config.loggerCallback=o.loggerCallback||this.config.loggerCallback,this.config.winlogCallback=o.winlogCallback||this.config.winlogCallback},r.prototype.logToServer=function(o){var t=void 0,e="";e="object"===(void 0===o?"undefined":n(o))?JSON.stringify(o):o;var r=this.config.serverFileUrl+"?error="+encodeURIComponent(e);if(window.XMLHttpRequest)t=new XMLHttpRequest;else{if(!window.ActiveXObject)return;t=new ActiveXObject("Microsoft.XMLHTTP")}t.open("GET",r),t.send()},r.prototype.bindOnError=function(){var o=this;window.onerror=function(t,e,r,n){var i=t+" : "+e+" : Line "+r+" : Char "+n;return o.log(i,"Error",r),!0}},t.exports=r},{}],"3":[function(o,t,e){"use strict";function r(o){this.config=o,this.debugMode=this.config.debugMode,this.data={}}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o};r.prototype.log=function(o){var t=o;if(this.debugMode){var e=Date.now();if(this.data[e]=t,"object"===("undefined"==typeof localStorage?"undefined":n(localStorage))){try{t=JSON.stringify(t)}catch(o){t="Unable to stringify the incoming message object : "+o.message}try{localStorage.setItem(e,t)}catch(o){this.output("Local storage error: "+o)}}this.output(t)}},r.prototype.getPersistentData=function(){if(localStorage)if(localStorage.length>0){var o=void 0,t=void 0,e=void 0,r=void 0;for(this.output("/***** Output local storage *****/"),o=0;o<localStorage.length;o++)t=Number(localStorage.key(o)),e=localStorage[t],"Invalid Date"!==(r=new Date(t))&&this.output(r+" => "+e);this.output("/***** End of local storage *****/")}else this.output("Local storage is empty");else this.output("Local storage not available")},r.prototype.clearPersistentData=function(){localStorage&&(localStorage.clear(),this.output("Local storage cleared"))},r.prototype.output=function(o){void 0!==window.console&&window.console.log(o)},Date.now||(Date.now=function(){return(new Date).getTime()}),t.exports=r},{}]},{},[1]); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@justeat/f-logger", | ||
"description": "Client-side logging, error-logging and debugging utils", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "./dist/index.js", | ||
@@ -23,3 +23,3 @@ "files": [ | ||
"devDependencies": { | ||
"@justeat/gulp-build-fozzie": "^7.5.0", | ||
"@justeat/gulp-build-fozzie": "^7.13.0", | ||
"babel-preset-env": "^1.6.1", | ||
@@ -26,0 +26,0 @@ "concurrently": "^3.5.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
72973
310