argon-logger
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -5,3 +5,3 @@ /**! | ||
* @author Sachin Singh <contactsachinsingh@gmail.com> | ||
* @version v0.1.2 | ||
* @version v0.2.0 | ||
* @license MIT | ||
@@ -104,2 +104,14 @@ */ | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _arrayWithHoles(arr) { | ||
@@ -109,2 +121,6 @@ if (Array.isArray(arr)) return arr; | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
@@ -140,2 +156,6 @@ if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _nonIterableRest() { | ||
@@ -258,3 +278,7 @@ throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
if (typeof this.config.test === 'function') { | ||
return this.config.test(); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return this.config.test.apply(this.config, args); | ||
} | ||
@@ -282,3 +306,4 @@ | ||
allowedQueryStringParameters: ['debug'], | ||
allowedPorts: [] | ||
allowedPorts: [], | ||
prefixes: [] | ||
}, config)); | ||
@@ -291,4 +316,4 @@ this.location = typeof window === 'undefined' ? {} : window.location; | ||
key: "isLoggingAllowed", | ||
value: function isLoggingAllowed() { | ||
return _isLoggingAllowed.apply(this); | ||
value: function isLoggingAllowed(args) { | ||
return _isLoggingAllowed.apply(this, args); | ||
} | ||
@@ -298,6 +323,8 @@ }, { | ||
value: function log() { | ||
if (this.isLoggingAllowed() && console.log) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.log) { | ||
var _console; | ||
return (_console = console).log.apply(_console, arguments); | ||
return (_console = console).log.apply(_console, _toConsumableArray(args)); | ||
} | ||
@@ -308,6 +335,8 @@ } | ||
value: function warn() { | ||
if (this.isLoggingAllowed() && console.warn) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.warn) { | ||
var _console2; | ||
(_console2 = console).warn.apply(_console2, arguments); | ||
(_console2 = console).warn.apply(_console2, _toConsumableArray(args)); | ||
} | ||
@@ -318,6 +347,8 @@ } | ||
value: function debug() { | ||
if (this.isLoggingAllowed() && console.debug) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.debug) { | ||
var _console3; | ||
(_console3 = console).debug.apply(_console3, arguments); | ||
(_console3 = console).debug.apply(_console3, _toConsumableArray(args)); | ||
} | ||
@@ -328,6 +359,8 @@ } | ||
value: function error() { | ||
if (this.isLoggingAllowed() && console.error) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.error) { | ||
var _console4; | ||
(_console4 = console).error.apply(_console4, arguments); | ||
(_console4 = console).error.apply(_console4, _toConsumableArray(args)); | ||
} | ||
@@ -338,6 +371,8 @@ } | ||
value: function info() { | ||
if (this.isLoggingAllowed() && console.info) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.info) { | ||
var _console5; | ||
(_console5 = console).info.apply(_console5, arguments); | ||
(_console5 = console).info.apply(_console5, _toConsumableArray(args)); | ||
} | ||
@@ -348,6 +383,8 @@ } | ||
value: function dir() { | ||
if (this.isLoggingAllowed() && console.dir) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.dir) { | ||
var _console6; | ||
(_console6 = console).dir.apply(_console6, arguments); | ||
(_console6 = console).dir.apply(_console6, _toConsumableArray(args)); | ||
} | ||
@@ -358,6 +395,8 @@ } | ||
value: function dirxml() { | ||
if (this.isLoggingAllowed() && console.dirxml) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.dirxml) { | ||
var _console7; | ||
(_console7 = console).dirxml.apply(_console7, arguments); | ||
(_console7 = console).dirxml.apply(_console7, _toConsumableArray(args)); | ||
} | ||
@@ -368,6 +407,8 @@ } | ||
value: function table() { | ||
if (this.isLoggingAllowed() && console.table) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.table) { | ||
var _console8; | ||
(_console8 = console).table.apply(_console8, arguments); | ||
(_console8 = console).table.apply(_console8, _toConsumableArray(args)); | ||
} | ||
@@ -378,6 +419,8 @@ } | ||
value: function trace() { | ||
if (this.isLoggingAllowed() && console.trace) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.trace) { | ||
var _console9; | ||
(_console9 = console).trace.apply(_console9, arguments); | ||
(_console9 = console).trace.apply(_console9, _toConsumableArray(args)); | ||
} | ||
@@ -388,6 +431,8 @@ } | ||
value: function group() { | ||
if (this.isLoggingAllowed() && console.group) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.group) { | ||
var _console10; | ||
(_console10 = console).group.apply(_console10, arguments); | ||
(_console10 = console).group.apply(_console10, _toConsumableArray(args)); | ||
} | ||
@@ -398,6 +443,8 @@ } | ||
value: function groupCollapsed() { | ||
if (this.isLoggingAllowed() && console.groupCollapsed) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.groupCollapsed) { | ||
var _console11; | ||
(_console11 = console).groupCollapsed.apply(_console11, arguments); | ||
(_console11 = console).groupCollapsed.apply(_console11, _toConsumableArray(args)); | ||
} | ||
@@ -408,6 +455,8 @@ } | ||
value: function groupEnd() { | ||
if (this.isLoggingAllowed() && console.groupEnd) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.groupEnd) { | ||
var _console12; | ||
(_console12 = console).groupEnd.apply(_console12, arguments); | ||
(_console12 = console).groupEnd.apply(_console12, _toConsumableArray(args)); | ||
} | ||
@@ -418,6 +467,8 @@ } | ||
value: function clear() { | ||
if (this.isLoggingAllowed() && console.clear) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.clear) { | ||
var _console13; | ||
(_console13 = console).clear.apply(_console13, arguments); | ||
(_console13 = console).clear.apply(_console13, _toConsumableArray(args)); | ||
} | ||
@@ -428,6 +479,8 @@ } | ||
value: function count() { | ||
if (this.isLoggingAllowed() && console.count) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.count) { | ||
var _console14; | ||
(_console14 = console).count.apply(_console14, arguments); | ||
(_console14 = console).count.apply(_console14, _toConsumableArray(args)); | ||
} | ||
@@ -438,6 +491,8 @@ } | ||
value: function countReset() { | ||
if (this.isLoggingAllowed() && console.countReset) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.countReset) { | ||
var _console15; | ||
(_console15 = console).countReset.apply(_console15, arguments); | ||
(_console15 = console).countReset.apply(_console15, _toConsumableArray(args)); | ||
} | ||
@@ -448,6 +503,8 @@ } | ||
value: function assert() { | ||
if (this.isLoggingAllowed() && console.assert) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.assert) { | ||
var _console16; | ||
(_console16 = console).assert.apply(_console16, arguments); | ||
(_console16 = console).assert.apply(_console16, _toConsumableArray(args)); | ||
} | ||
@@ -458,6 +515,8 @@ } | ||
value: function profile() { | ||
if (this.isLoggingAllowed() && console.profile) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.profile) { | ||
var _console17; | ||
(_console17 = console).profile.apply(_console17, arguments); | ||
(_console17 = console).profile.apply(_console17, _toConsumableArray(args)); | ||
} | ||
@@ -468,6 +527,8 @@ } | ||
value: function profileEnd() { | ||
if (this.isLoggingAllowed() && console.profileEnd) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.profileEnd) { | ||
var _console18; | ||
(_console18 = console).profileEnd.apply(_console18, arguments); | ||
(_console18 = console).profileEnd.apply(_console18, _toConsumableArray(args)); | ||
} | ||
@@ -478,6 +539,8 @@ } | ||
value: function time() { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed() && console.time) { | ||
var _console19; | ||
(_console19 = console).time.apply(_console19, arguments); | ||
(_console19 = console).time.apply(_console19, _toConsumableArray(args)); | ||
} | ||
@@ -488,6 +551,8 @@ } | ||
value: function timeLog() { | ||
if (this.isLoggingAllowed() && console.timeLog) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.timeLog) { | ||
var _console20; | ||
(_console20 = console).timeLog.apply(_console20, arguments); | ||
(_console20 = console).timeLog.apply(_console20, _toConsumableArray(args)); | ||
} | ||
@@ -498,6 +563,8 @@ } | ||
value: function timeStamp() { | ||
if (this.isLoggingAllowed() && console.timeStamp) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.timeStamp) { | ||
var _console21; | ||
(_console21 = console).timeStamp.apply(_console21, arguments); | ||
(_console21 = console).timeStamp.apply(_console21, _toConsumableArray(args)); | ||
} | ||
@@ -508,6 +575,8 @@ } | ||
value: function context() { | ||
if (this.isLoggingAllowed() && console.context) { | ||
var args = [].concat(_toConsumableArray(this.config.prefixes), Array.prototype.slice.call(arguments)); | ||
if (this.isLoggingAllowed(args) && console.context) { | ||
var _console22; | ||
(_console22 = console).context.apply(_console22, arguments); | ||
(_console22 = console).context.apply(_console22, _toConsumableArray(args)); | ||
} | ||
@@ -514,0 +583,0 @@ } |
@@ -5,5 +5,5 @@ /**! | ||
* @author Sachin Singh <contactsachinsingh@gmail.com> | ||
* @version v0.1.2 | ||
* @version v0.2.0 | ||
* @license MIT | ||
*/ | ||
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).Logger=o()}(this,(function(){"use strict";function e(o){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(o)}function o(e,o){for(var n=0;n<o.length;n++){var t=o[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function n(e,o,n){return o in e?Object.defineProperty(e,o,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[o]=n,e}function t(e,o){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);o&&(t=t.filter((function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable}))),n.push.apply(n,t)}return n}function r(e,o){return function(e){if(Array.isArray(e))return e}(e)||function(e,o){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],t=!0,r=!1,l=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done)&&(n.push(i.value),!o||n.length!==o);t=!0);}catch(e){r=!0,l=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw l}}return n}(e,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function l(e,o){return Object.prototype.hasOwnProperty.call(e,o)}function i(o,n){var t=Array.isArray(n.allowedQueryStringParameters)?n.allowedQueryStringParameters:[],i=function(e){return(e=e.substring("?"===e.charAt(0)?1:0)).split("&").map((function(e){var o=r(e.split("=").map((function(e){return decodeURIComponent(e).trim()})),2);return{key:o[0],value:o[1]}}))}(o),a=[];t.forEach((function(o){if("string"==typeof o){var n=r(o.split("="),2),t=n[0],i=n[1],c=void 0===i||i;a.push({key:t,value:c})}else o&&"object"===e(o)&&l(o,"key")&&l(o,"value")&&(o.key=o.key.trim(),o.value="".concat(o.value).trim(),a.push(o))}));var c=!1;return a.forEach((function(e){var o=!!i.filter((function(o){return e.key===o.key&&(e.value===o.value||!0===e.value)})).length;c=c||o})),c}function a(){return"function"==typeof this.config.test?this.config.test():"undefined"!=typeof console&&(e=this.location.hostname,o=this.config,(0===(n=Array.isArray(o.allowedHostnames)?o.allowedHostnames:[]).length||!!n.filter((function(o){return o.indexOf(e)>-1})).length)&&function(e,o){var n=Array.isArray(o.allowedPorts)?o.allowedPorts:[];return 0===(n=n.map((function(e){return"".concat(e).trim()}))).length||n.indexOf(e)>-1}(this.location.port,this.config)||i(this.location.search,this.config))&&!this.config.disable;var e,o,n}return function(){function e(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=Object.freeze(function(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?t(Object(r),!0).forEach((function(o){n(e,o,r[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))}))}return e}({allowedHostnames:["localhost","127.0.0.1","0.0.0.0"],disable:!1,allowedQueryStringParameters:["debug"],allowedPorts:[]},o)),this.location="undefined"==typeof window?{}:window.location,this.URL=this.location.href}var r,l,i;return r=e,(l=[{key:"isLoggingAllowed",value:function(){return a.apply(this)}},{key:"log",value:function(){var e;if(this.isLoggingAllowed()&&console.log)return(e=console).log.apply(e,arguments)}},{key:"warn",value:function(){var e;this.isLoggingAllowed()&&console.warn&&(e=console).warn.apply(e,arguments)}},{key:"debug",value:function(){var e;this.isLoggingAllowed()&&console.debug&&(e=console).debug.apply(e,arguments)}},{key:"error",value:function(){var e;this.isLoggingAllowed()&&console.error&&(e=console).error.apply(e,arguments)}},{key:"info",value:function(){var e;this.isLoggingAllowed()&&console.info&&(e=console).info.apply(e,arguments)}},{key:"dir",value:function(){var e;this.isLoggingAllowed()&&console.dir&&(e=console).dir.apply(e,arguments)}},{key:"dirxml",value:function(){var e;this.isLoggingAllowed()&&console.dirxml&&(e=console).dirxml.apply(e,arguments)}},{key:"table",value:function(){var e;this.isLoggingAllowed()&&console.table&&(e=console).table.apply(e,arguments)}},{key:"trace",value:function(){var e;this.isLoggingAllowed()&&console.trace&&(e=console).trace.apply(e,arguments)}},{key:"group",value:function(){var e;this.isLoggingAllowed()&&console.group&&(e=console).group.apply(e,arguments)}},{key:"groupCollapsed",value:function(){var e;this.isLoggingAllowed()&&console.groupCollapsed&&(e=console).groupCollapsed.apply(e,arguments)}},{key:"groupEnd",value:function(){var e;this.isLoggingAllowed()&&console.groupEnd&&(e=console).groupEnd.apply(e,arguments)}},{key:"clear",value:function(){var e;this.isLoggingAllowed()&&console.clear&&(e=console).clear.apply(e,arguments)}},{key:"count",value:function(){var e;this.isLoggingAllowed()&&console.count&&(e=console).count.apply(e,arguments)}},{key:"countReset",value:function(){var e;this.isLoggingAllowed()&&console.countReset&&(e=console).countReset.apply(e,arguments)}},{key:"assert",value:function(){var e;this.isLoggingAllowed()&&console.assert&&(e=console).assert.apply(e,arguments)}},{key:"profile",value:function(){var e;this.isLoggingAllowed()&&console.profile&&(e=console).profile.apply(e,arguments)}},{key:"profileEnd",value:function(){var e;this.isLoggingAllowed()&&console.profileEnd&&(e=console).profileEnd.apply(e,arguments)}},{key:"time",value:function(){var e;this.isLoggingAllowed()&&console.time&&(e=console).time.apply(e,arguments)}},{key:"timeLog",value:function(){var e;this.isLoggingAllowed()&&console.timeLog&&(e=console).timeLog.apply(e,arguments)}},{key:"timeStamp",value:function(){var e;this.isLoggingAllowed()&&console.timeStamp&&(e=console).timeStamp.apply(e,arguments)}},{key:"context",value:function(){var e;this.isLoggingAllowed()&&console.context&&(e=console).context.apply(e,arguments)}}])&&o(r.prototype,l),i&&o(r,i),e}()})); | ||
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).Logger=o()}(this,(function(){"use strict";function e(o){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(o)}function o(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function t(e,o,t){return o in e?Object.defineProperty(e,o,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[o]=t,e}function n(e,o){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);o&&(n=n.filter((function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable}))),t.push.apply(t,n)}return t}function r(e,o){return function(e){if(Array.isArray(e))return e}(e)||function(e,o){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],n=!0,r=!1,i=void 0;try{for(var l,c=e[Symbol.iterator]();!(n=(l=c.next()).done)&&(t.push(l.value),!o||t.length!==o);n=!0);}catch(e){r=!0,i=e}finally{try{n||null==c.return||c.return()}finally{if(r)throw i}}return t}(e,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(e){return function(e){if(Array.isArray(e)){for(var o=0,t=new Array(e.length);o<e.length;o++)t[o]=e[o];return t}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function l(e,o){return Object.prototype.hasOwnProperty.call(e,o)}function c(o,t){var n=Array.isArray(t.allowedQueryStringParameters)?t.allowedQueryStringParameters:[],i=function(e){return(e=e.substring("?"===e.charAt(0)?1:0)).split("&").map((function(e){var o=r(e.split("=").map((function(e){return decodeURIComponent(e).trim()})),2);return{key:o[0],value:o[1]}}))}(o),c=[];n.forEach((function(o){if("string"==typeof o){var t=r(o.split("="),2),n=t[0],i=t[1],a=void 0===i||i;c.push({key:n,value:a})}else o&&"object"===e(o)&&l(o,"key")&&l(o,"value")&&(o.key=o.key.trim(),o.value="".concat(o.value).trim(),c.push(o))}));var a=!1;return c.forEach((function(e){var o=!!i.filter((function(o){return e.key===o.key&&(e.value===o.value||!0===e.value)})).length;a=a||o})),a}function a(){if("function"==typeof this.config.test){for(var e=arguments.length,o=new Array(e),t=0;t<e;t++)o[t]=arguments[t];return this.config.test.apply(this.config,o)}return"undefined"!=typeof console&&(n=this.location.hostname,r=this.config,(0===(i=Array.isArray(r.allowedHostnames)?r.allowedHostnames:[]).length||!!i.filter((function(e){return e.indexOf(n)>-1})).length)&&function(e,o){var t=Array.isArray(o.allowedPorts)?o.allowedPorts:[];return 0===(t=t.map((function(e){return"".concat(e).trim()}))).length||t.indexOf(e)>-1}(this.location.port,this.config)||c(this.location.search,this.config))&&!this.config.disable;var n,r,i}return function(){function e(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=Object.freeze(function(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?n(Object(r),!0).forEach((function(o){t(e,o,r[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))}))}return e}({allowedHostnames:["localhost","127.0.0.1","0.0.0.0"],disable:!1,allowedQueryStringParameters:["debug"],allowedPorts:[],prefixes:[]},o)),this.location="undefined"==typeof window?{}:window.location,this.URL=this.location.href}var r,l,c;return r=e,(l=[{key:"isLoggingAllowed",value:function(e){return a.apply(this,e)}},{key:"log",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));if(this.isLoggingAllowed(o)&&console.log)return(e=console).log.apply(e,i(o))}},{key:"warn",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.warn&&(e=console).warn.apply(e,i(o))}},{key:"debug",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.debug&&(e=console).debug.apply(e,i(o))}},{key:"error",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.error&&(e=console).error.apply(e,i(o))}},{key:"info",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.info&&(e=console).info.apply(e,i(o))}},{key:"dir",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.dir&&(e=console).dir.apply(e,i(o))}},{key:"dirxml",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.dirxml&&(e=console).dirxml.apply(e,i(o))}},{key:"table",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.table&&(e=console).table.apply(e,i(o))}},{key:"trace",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.trace&&(e=console).trace.apply(e,i(o))}},{key:"group",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.group&&(e=console).group.apply(e,i(o))}},{key:"groupCollapsed",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.groupCollapsed&&(e=console).groupCollapsed.apply(e,i(o))}},{key:"groupEnd",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.groupEnd&&(e=console).groupEnd.apply(e,i(o))}},{key:"clear",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.clear&&(e=console).clear.apply(e,i(o))}},{key:"count",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.count&&(e=console).count.apply(e,i(o))}},{key:"countReset",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.countReset&&(e=console).countReset.apply(e,i(o))}},{key:"assert",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.assert&&(e=console).assert.apply(e,i(o))}},{key:"profile",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.profile&&(e=console).profile.apply(e,i(o))}},{key:"profileEnd",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.profileEnd&&(e=console).profileEnd.apply(e,i(o))}},{key:"time",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed()&&console.time&&(e=console).time.apply(e,i(o))}},{key:"timeLog",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.timeLog&&(e=console).timeLog.apply(e,i(o))}},{key:"timeStamp",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.timeStamp&&(e=console).timeStamp.apply(e,i(o))}},{key:"context",value:function(){var e,o=[].concat(i(this.config.prefixes),Array.prototype.slice.call(arguments));this.isLoggingAllowed(o)&&console.context&&(e=console).context.apply(e,i(o))}}])&&o(r.prototype,l),c&&o(r,c),e}()})); |
{ | ||
"name": "argon-logger", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A simple console logging utility", | ||
@@ -5,0 +5,0 @@ "main": "dist/js/argonLogger", |
@@ -37,4 +37,5 @@ # Argon logger [![Build Status](https://travis-ci.org/scssyworks/argon-logger.svg?branch=master)](https://travis-ci.org/scssyworks/argon-logger) | ||
allowedPorts: [], // List of ports for which logging should be enabled | ||
test: () => { ... }, // A test function for full flexibility on customizing where to hide the logs | ||
test: (...logArguments) => { ... }, // A test function for full flexibility on customizing where to hide the logs | ||
// A test function overrides existing filters. | ||
prefixes: [], // Array of strings to be prepended automatically before each log. | ||
disable: false // If set to "true" disables the logging completely. The remaining two parameters are ignored. | ||
@@ -50,2 +51,2 @@ }); | ||
Argon logger doesn't have any major releases yet. It means it has potential to break in few scenarios. We need your contribution to make it better. Please email at <a href="mailto:contactsachinsingh@gmail.com">contactsachinsingh@gmail.com</a> if you want to become a contributor. | ||
Argon logger doesn't have any major releases yet. Your contribution can help us improve this project. Let us know if you have any suggestions for improvements and features. |
117
src/index.js
@@ -87,5 +87,5 @@ /** | ||
*/ | ||
function isLoggingAllowed() { | ||
function isLoggingAllowed(...args) { | ||
if (typeof this.config.test === 'function') { | ||
return this.config.test(); | ||
return this.config.test.apply(this.config, args); | ||
} | ||
@@ -116,2 +116,3 @@ return ( | ||
allowedPorts: [], | ||
prefixes: [], | ||
...config | ||
@@ -122,115 +123,137 @@ }); | ||
} | ||
isLoggingAllowed() { | ||
return isLoggingAllowed.apply(this); | ||
isLoggingAllowed(args) { | ||
return isLoggingAllowed.apply(this, args); | ||
} | ||
log() { | ||
if (this.isLoggingAllowed() && console.log) { | ||
return console.log(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.log) { | ||
return console.log(...args); | ||
} | ||
} | ||
warn() { | ||
if (this.isLoggingAllowed() && console.warn) { | ||
console.warn(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.warn) { | ||
console.warn(...args); | ||
} | ||
} | ||
debug() { | ||
if (this.isLoggingAllowed() && console.debug) { | ||
console.debug(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.debug) { | ||
console.debug(...args); | ||
} | ||
} | ||
error() { | ||
if (this.isLoggingAllowed() && console.error) { | ||
console.error(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.error) { | ||
console.error(...args); | ||
} | ||
} | ||
info() { | ||
if (this.isLoggingAllowed() && console.info) { | ||
console.info(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.info) { | ||
console.info(...args); | ||
} | ||
} | ||
dir() { | ||
if (this.isLoggingAllowed() && console.dir) { | ||
console.dir(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.dir) { | ||
console.dir(...args); | ||
} | ||
} | ||
dirxml() { | ||
if (this.isLoggingAllowed() && console.dirxml) { | ||
console.dirxml(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.dirxml) { | ||
console.dirxml(...args); | ||
} | ||
} | ||
table() { | ||
if (this.isLoggingAllowed() && console.table) { | ||
console.table(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.table) { | ||
console.table(...args); | ||
} | ||
} | ||
trace() { | ||
if (this.isLoggingAllowed() && console.trace) { | ||
console.trace(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.trace) { | ||
console.trace(...args); | ||
} | ||
} | ||
group() { | ||
if (this.isLoggingAllowed() && console.group) { | ||
console.group(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.group) { | ||
console.group(...args); | ||
} | ||
} | ||
groupCollapsed() { | ||
if (this.isLoggingAllowed() && console.groupCollapsed) { | ||
console.groupCollapsed(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.groupCollapsed) { | ||
console.groupCollapsed(...args); | ||
} | ||
} | ||
groupEnd() { | ||
if (this.isLoggingAllowed() && console.groupEnd) { | ||
console.groupEnd(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.groupEnd) { | ||
console.groupEnd(...args); | ||
} | ||
} | ||
clear() { | ||
if (this.isLoggingAllowed() && console.clear) { | ||
console.clear(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.clear) { | ||
console.clear(...args); | ||
} | ||
} | ||
count() { | ||
if (this.isLoggingAllowed() && console.count) { | ||
console.count(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.count) { | ||
console.count(...args); | ||
} | ||
} | ||
countReset() { | ||
if (this.isLoggingAllowed() && console.countReset) { | ||
console.countReset(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.countReset) { | ||
console.countReset(...args); | ||
} | ||
} | ||
assert() { | ||
if (this.isLoggingAllowed() && console.assert) { | ||
console.assert(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.assert) { | ||
console.assert(...args); | ||
} | ||
} | ||
profile() { | ||
if (this.isLoggingAllowed() && console.profile) { | ||
console.profile(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.profile) { | ||
console.profile(...args); | ||
} | ||
} | ||
profileEnd() { | ||
if (this.isLoggingAllowed() && console.profileEnd) { | ||
console.profileEnd(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.profileEnd) { | ||
console.profileEnd(...args); | ||
} | ||
} | ||
time() { | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed() && console.time) { | ||
console.time(...arguments); | ||
console.time(...args); | ||
} | ||
} | ||
timeLog() { | ||
if (this.isLoggingAllowed() && console.timeLog) { | ||
console.timeLog(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.timeLog) { | ||
console.timeLog(...args); | ||
} | ||
} | ||
timeStamp() { | ||
if (this.isLoggingAllowed() && console.timeStamp) { | ||
console.timeStamp(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.timeStamp) { | ||
console.timeStamp(...args); | ||
} | ||
} | ||
context() { | ||
if (this.isLoggingAllowed() && console.context) { | ||
console.context(...arguments); | ||
const args = [...this.config.prefixes, ...arguments]; | ||
if (this.isLoggingAllowed(args) && console.context) { | ||
console.context(...args); | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ declare class Logger { | ||
location: object; | ||
isLoggingAllowed(): boolean; | ||
isLoggingAllowed(args: any[]): boolean; | ||
debug(...args: any): any; | ||
@@ -37,3 +37,4 @@ error(...args: any): any; | ||
allowedPorts?: string[], | ||
disable?: boolean | ||
disable?: boolean, | ||
prefixes?: string[] | ||
} | ||
@@ -40,0 +41,0 @@ } |
Sorry, the diff of this file is not supported yet
59855
874
50