MDL-67376 libraries: Upgrade loglevel.js to version 1.6.6

This commit is contained in:
Shamim Rezaie
2019-12-11 21:28:52 +11:00
parent 8cf4c97217
commit 4bee39d31c
4 changed files with 132 additions and 121 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}(function(a,b){"use strict";if("function"==typeof define&&define.amd){define ("core/loglevel",b)}else if("object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports){module.exports=b()}else{a.log=b()}})(this,function(){"use strict";var g=function(){},h="undefined",j=["trace","debug","info","warn","error"];function a(a,b){var c=a[b];if("function"==typeof c.bind){return c.bind(a)}else{try{return Function.prototype.bind.call(c,a)}catch(b){return function(){return Function.prototype.apply.apply(c,[a,arguments])}}}}function b(b){if("debug"===b){b="log"}if(("undefined"==typeof console?"undefined":_typeof(console))===h){return!1}else if(console[b]!==void 0){return a(console,b)}else if(console.log!==void 0){return a(console,"log")}else{return g}}function c(a,b){for(var c=0,d;c<j.length;c++){d=j[c];this[d]=c<a?g:this.methodFactory(d,a,b)}this.log=this.debug}function d(a,b,d){return function(){if(("undefined"==typeof console?"undefined":_typeof(console))!==h){c.call(this,b,d);this[a].apply(this,arguments)}}}function e(a){return b(a)||d.apply(this,arguments)}function f(a,b,d){var i=this,k,l="loglevel";if(a){l+=":"+a}function f(a){var b=(j[a]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":_typeof(window))===h)return;try{window.localStorage[l]=b;return}catch(a){}try{window.document.cookie=encodeURIComponent(l)+"="+b+";"}catch(a){}}function g(){var a;if(("undefined"==typeof window?"undefined":_typeof(window))===h)return;try{a=window.localStorage[l]}catch(a){}if(_typeof(a)===h){try{var b=window.document.cookie,c=b.indexOf(encodeURIComponent(l)+"=");if(-1!==c){a=/^([^;]+)/.exec(b.slice(c))[1]}}catch(a){}}if(i.levels[a]===void 0){a=void 0}return a}i.name=a;i.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5};i.methodFactory=d||e;i.getLevel=function(){return k};i.setLevel=function(b,d){if("string"==typeof b&&i.levels[b.toUpperCase()]!==void 0){b=i.levels[b.toUpperCase()]}if("number"==typeof b&&0<=b&&b<=i.levels.SILENT){k=b;if(!1!==d){f(b)}c.call(i,b,a);if(("undefined"==typeof console?"undefined":_typeof(console))===h&&b<i.levels.SILENT){return"No console available for logging"}}else{throw"log.setLevel() called with invalid level: "+b}};i.setDefaultLevel=function(a){if(!g()){i.setLevel(a,!1)}};i.enableAll=function(a){i.setLevel(i.levels.TRACE,a)};i.disableAll=function(a){i.setLevel(i.levels.SILENT,a)};var m=g();if(null==m){m=null==b?"WARN":b}i.setLevel(m,!1)}var k=new f,l={};k.getLogger=function(a){if("string"!=typeof a||""===a){throw new TypeError("You must supply a name when creating a logger.")}var b=l[a];if(!b){b=l[a]=new f(a,k.getLevel(),k.methodFactory)}return b};var m=("undefined"==typeof window?"undefined":_typeof(window))!==h?window.log:void 0;k.noConflict=function(){if(("undefined"==typeof window?"undefined":_typeof(window))!==h&&window.log===k){window.log=m}return k};k.getLoggers=function(){return l};return k});
function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}(function(a,b){"use strict";if("function"==typeof define&&define.amd){define ("core/loglevel",b)}else if("object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports){module.exports=b()}else{a.log=b()}})(this,function(){"use strict";var h=function(){},i="undefined",j=("undefined"==typeof window?"undefined":_typeof(window))!==i&&/Trident\/|MSIE /.test(window.navigator.userAgent),k=["trace","debug","info","warn","error"];function a(a,b){var c=a[b];if("function"==typeof c.bind){return c.bind(a)}else{try{return Function.prototype.bind.call(c,a)}catch(b){return function(){return Function.prototype.apply.apply(c,[a,arguments])}}}}function b(){if(console.log){if(console.log.apply){console.log.apply(console,arguments)}else{Function.prototype.apply.apply(console.log,[console,arguments])}}if(console.trace)console.trace()}function c(c){if("debug"===c){c="log"}if(("undefined"==typeof console?"undefined":_typeof(console))===i){return!1}else if("trace"===c&&j){return b}else if(console[c]!==void 0){return a(console,c)}else if(console.log!==void 0){return a(console,"log")}else{return h}}function d(a,b){for(var c=0,d;c<k.length;c++){d=k[c];this[d]=c<a?h:this.methodFactory(d,a,b)}this.log=this.debug}function e(a,b,c){return function(){if(("undefined"==typeof console?"undefined":_typeof(console))!==i){d.call(this,b,c);this[a].apply(this,arguments)}}}function f(a){return c(a)||e.apply(this,arguments)}function g(a,b,c){var h=this,j,l="loglevel";if(a){l+=":"+a}function e(a){var b=(k[a]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":_typeof(window))===i)return;try{window.localStorage[l]=b;return}catch(a){}try{window.document.cookie=encodeURIComponent(l)+"="+b+";"}catch(a){}}function g(){var a;if(("undefined"==typeof window?"undefined":_typeof(window))===i)return;try{a=window.localStorage[l]}catch(a){}if(_typeof(a)===i){try{var b=window.document.cookie,c=b.indexOf(encodeURIComponent(l)+"=");if(-1!==c){a=/^([^;]+)/.exec(b.slice(c))[1]}}catch(a){}}if(h.levels[a]===void 0){a=void 0}return a}h.name=a;h.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5};h.methodFactory=c||f;h.getLevel=function(){return j};h.setLevel=function(b,c){if("string"==typeof b&&h.levels[b.toUpperCase()]!==void 0){b=h.levels[b.toUpperCase()]}if("number"==typeof b&&0<=b&&b<=h.levels.SILENT){j=b;if(!1!==c){e(b)}d.call(h,b,a);if(("undefined"==typeof console?"undefined":_typeof(console))===i&&b<h.levels.SILENT){return"No console available for logging"}}else{throw"log.setLevel() called with invalid level: "+b}};h.setDefaultLevel=function(a){if(!g()){h.setLevel(a,!1)}};h.enableAll=function(a){h.setLevel(h.levels.TRACE,a)};h.disableAll=function(a){h.setLevel(h.levels.SILENT,a)};var m=g();if(null==m){m=null==b?"WARN":b}h.setLevel(m,!1)}var l=new g,m={};l.getLogger=function(a){if("string"!=typeof a||""===a){throw new TypeError("You must supply a name when creating a logger.")}var b=m[a];if(!b){b=m[a]=new g(a,l.getLevel(),l.methodFactory)}return b};var n=("undefined"==typeof window?"undefined":_typeof(window))!==i?window.log:void 0;l.noConflict=function(){if(("undefined"==typeof window?"undefined":_typeof(window))!==i&&window.log===l){window.log=n}return l};l.getLoggers=function(){return m};return l});
//# sourceMappingURL=loglevel.min.js.map
File diff suppressed because one or more lines are too long
+129 -118
View File
@@ -1,39 +1,32 @@
// The MIT License
//
// Copyright (c) 2013 Tim Perry
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// Description of import into Moodle:
// Download from https://github.com/pimterry/loglevel/dist
// Download from https://github.com/pimterry/loglevel/tree/master/dist
// Copy loglevel.js into lib/amd/src/ in Moodle folder.
// Add the license as a comment to the file and these instructions.
/*
* loglevel - https://github.com/pimterry/loglevel
*
* Copyright (c) 2013 Tim Perry
* Licensed under the MIT license.
*/
/*! loglevel - v1.6.2 - https://github.com/pimterry/loglevel - (c) 2019 Tim Perry - licensed MIT */
/*! loglevel - v1.6.6 - https://github.com/pimterry/loglevel - (c) 2019 Tim Perry - licensed MIT */
(function (root, definition) {
"use strict";
if (typeof define === 'function' && define.amd) {
@@ -49,6 +42,9 @@
// Slightly dubious tricks to cut down minimized file size
var noop = function() {};
var undefinedType = "undefined";
var isIE = (typeof window !== undefinedType) && (
/Trident\/|MSIE /.test(window.navigator.userAgent)
);
var logMethods = [
"trace",
@@ -75,6 +71,19 @@
}
}
// Trace() doesn't print the message in IE, so for that case we need to wrap it
function traceForIE() {
if (console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
// In old IE, native console methods themselves don't have apply().
Function.prototype.apply.apply(console.log, [console, arguments]);
}
}
if (console.trace) console.trace();
}
// Build the best logging method possible for this env
// Wherever possible we want to bind, not wrap, to preserve stack traces
function realMethod(methodName) {
@@ -84,6 +93,8 @@
if (typeof console === undefinedType) {
return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
} else if (methodName === 'trace' && isIE) {
return traceForIE;
} else if (console[methodName] !== undefined) {
return bindMethod(console, methodName);
} else if (console.log !== undefined) {
@@ -124,119 +135,119 @@
function defaultMethodFactory(methodName, level, loggerName) {
/*jshint validthis:true */
return realMethod(methodName) ||
enableLoggingWhenConsoleArrives.apply(this, arguments);
enableLoggingWhenConsoleArrives.apply(this, arguments);
}
function Logger(name, defaultLevel, factory) {
var self = this;
var currentLevel;
var storageKey = "loglevel";
if (name) {
storageKey += ":" + name;
}
var self = this;
var currentLevel;
var storageKey = "loglevel";
if (name) {
storageKey += ":" + name;
}
function persistLevelIfPossible(levelNum) {
var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
function persistLevelIfPossible(levelNum) {
var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
if (typeof window === undefinedType) return;
if (typeof window === undefinedType) return;
// Use localStorage if available
try {
window.localStorage[storageKey] = levelName;
return;
} catch (ignore) {}
// Use localStorage if available
try {
window.localStorage[storageKey] = levelName;
return;
} catch (ignore) {}
// Use session cookie as fallback
try {
window.document.cookie =
encodeURIComponent(storageKey) + "=" + levelName + ";";
} catch (ignore) {}
}
// Use session cookie as fallback
try {
window.document.cookie =
encodeURIComponent(storageKey) + "=" + levelName + ";";
} catch (ignore) {}
}
function getPersistedLevel() {
var storedLevel;
function getPersistedLevel() {
var storedLevel;
if (typeof window === undefinedType) return;
if (typeof window === undefinedType) return;
try {
storedLevel = window.localStorage[storageKey];
} catch (ignore) {}
try {
storedLevel = window.localStorage[storageKey];
} catch (ignore) {}
// Fallback to cookies if local storage gives us nothing
if (typeof storedLevel === undefinedType) {
try {
var cookie = window.document.cookie;
var location = cookie.indexOf(
encodeURIComponent(storageKey) + "=");
if (location !== -1) {
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
}
} catch (ignore) {}
}
// Fallback to cookies if local storage gives us nothing
if (typeof storedLevel === undefinedType) {
try {
var cookie = window.document.cookie;
var location = cookie.indexOf(
encodeURIComponent(storageKey) + "=");
if (location !== -1) {
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
}
} catch (ignore) {}
}
// If the stored level is not valid, treat it as if nothing was stored.
if (self.levels[storedLevel] === undefined) {
storedLevel = undefined;
}
// If the stored level is not valid, treat it as if nothing was stored.
if (self.levels[storedLevel] === undefined) {
storedLevel = undefined;
}
return storedLevel;
}
return storedLevel;
}
/*
*
* Public logger API - see https://github.com/pimterry/loglevel for details
*
*/
/*
*
* Public logger API - see https://github.com/pimterry/loglevel for details
*
*/
self.name = name;
self.name = name;
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
"ERROR": 4, "SILENT": 5};
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
"ERROR": 4, "SILENT": 5};
self.methodFactory = factory || defaultMethodFactory;
self.methodFactory = factory || defaultMethodFactory;
self.getLevel = function () {
return currentLevel;
};
self.getLevel = function () {
return currentLevel;
};
self.setLevel = function (level, persist) {
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
level = self.levels[level.toUpperCase()];
}
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
currentLevel = level;
if (persist !== false) { // defaults to true
persistLevelIfPossible(level);
}
replaceLoggingMethods.call(self, level, name);
if (typeof console === undefinedType && level < self.levels.SILENT) {
return "No console available for logging";
}
} else {
throw "log.setLevel() called with invalid level: " + level;
}
};
self.setLevel = function (level, persist) {
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
level = self.levels[level.toUpperCase()];
}
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
currentLevel = level;
if (persist !== false) { // defaults to true
persistLevelIfPossible(level);
}
replaceLoggingMethods.call(self, level, name);
if (typeof console === undefinedType && level < self.levels.SILENT) {
return "No console available for logging";
}
} else {
throw "log.setLevel() called with invalid level: " + level;
}
};
self.setDefaultLevel = function (level) {
if (!getPersistedLevel()) {
self.setLevel(level, false);
}
};
self.setDefaultLevel = function (level) {
if (!getPersistedLevel()) {
self.setLevel(level, false);
}
};
self.enableAll = function(persist) {
self.setLevel(self.levels.TRACE, persist);
};
self.enableAll = function(persist) {
self.setLevel(self.levels.TRACE, persist);
};
self.disableAll = function(persist) {
self.setLevel(self.levels.SILENT, persist);
};
self.disableAll = function(persist) {
self.setLevel(self.levels.SILENT, persist);
};
// Initialize with the right level
var initialLevel = getPersistedLevel();
if (initialLevel == null) {
initialLevel = defaultLevel == null ? "WARN" : defaultLevel;
}
self.setLevel(initialLevel, false);
// Initialize with the right level
var initialLevel = getPersistedLevel();
if (initialLevel == null) {
initialLevel = defaultLevel == null ? "WARN" : defaultLevel;
}
self.setLevel(initialLevel, false);
}
/*
@@ -250,13 +261,13 @@
var _loggersByName = {};
defaultLogger.getLogger = function getLogger(name) {
if (typeof name !== "string" || name === "") {
throw new TypeError("You must supply a name when creating a logger.");
throw new TypeError("You must supply a name when creating a logger.");
}
var logger = _loggersByName[name];
if (!logger) {
logger = _loggersByName[name] = new Logger(
name, defaultLogger.getLevel(), defaultLogger.methodFactory);
logger = _loggersByName[name] = new Logger(
name, defaultLogger.getLevel(), defaultLogger.methodFactory);
}
return logger;
};
@@ -265,7 +276,7 @@
var _log = (typeof window !== undefinedType) ? window.log : undefined;
defaultLogger.noConflict = function() {
if (typeof window !== undefinedType &&
window.log === defaultLogger) {
window.log === defaultLogger) {
window.log = _log;
}
+1 -1
View File
@@ -186,7 +186,7 @@
<location>amd/src/loglevel.js</location>
<name>loglevel.js</name>
<license>MIT</license>
<version>1.6.2</version>
<version>1.6.6</version>
</library>
<library>
<location>mustache</location>