mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-56010-master' of git://github.com/lameze/moodle
This commit is contained in:
commit
109c3a1c57
2
lib/amd/build/loglevel.min.js
vendored
2
lib/amd/build/loglevel.min.js
vendored
@ -1 +1 @@
|
||||
!function(a,b){"use strict";"object"==typeof module&&module.exports&&"function"==typeof require?module.exports=b():"function"==typeof define&&"object"==typeof define.amd?define(b):a.log=b()}(this,function(){"use strict";function a(a){return typeof console!==h&&(void 0!==console[a]?b(console,a):void 0!==console.log?b(console,"log"):g)}function b(a,b){var c=a[b];if("function"==typeof c.bind)return c.bind(a);try{return Function.prototype.bind.call(c,a)}catch(d){return function(){return Function.prototype.apply.apply(c,[a,arguments])}}}function c(a,b,c){return function(){typeof console!==h&&(d.call(this,b,c),this[a].apply(this,arguments))}}function d(a,b){for(var c=0;c<i.length;c++){var d=i[c];this[d]=c<a?g:this.methodFactory(d,a,b)}}function e(b,d,e){return a(b)||c.apply(this,arguments)}function f(a,b,c){function f(a){var b=(i[a]||"silent").toUpperCase();try{return void(window.localStorage[l]=b)}catch(c){}try{window.document.cookie=encodeURIComponent(l)+"="+b+";"}catch(c){}}function g(){var a;try{a=window.localStorage[l]}catch(b){}if(typeof a===h)try{var c=window.document.cookie,d=c.indexOf(encodeURIComponent(l)+"=");d&&(a=/^([^;]+)/.exec(c.slice(d))[1])}catch(b){}return void 0===k.levels[a]&&(a=void 0),a}var j,k=this,l="loglevel";a&&(l+=":"+a),k.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},k.methodFactory=c||e,k.getLevel=function(){return j},k.setLevel=function(b,c){if("string"==typeof b&&void 0!==k.levels[b.toUpperCase()]&&(b=k.levels[b.toUpperCase()]),!("number"==typeof b&&b>=0&&b<=k.levels.SILENT))throw"log.setLevel() called with invalid level: "+b;if(j=b,c!==!1&&f(b),d.call(k,b,a),typeof console===h&&b<k.levels.SILENT)return"No console available for logging"},k.setDefaultLevel=function(a){g()||k.setLevel(a,!1)},k.enableAll=function(a){k.setLevel(k.levels.TRACE,a)},k.disableAll=function(a){k.setLevel(k.levels.SILENT,a)};var m=g();null==m&&(m=null==b?"WARN":b),k.setLevel(m,!1)}var g=function(){},h="undefined",i=["trace","debug","info","warn","error"],j=new f,k={};j.getLogger=function(a){if("string"!=typeof a||""===a)throw new TypeError("You must supply a name when creating a logger.");var b=k[a];return b||(b=k[a]=new f(a,j.getLevel(),j.methodFactory)),b};var l=typeof window!==h?window.log:void 0;return j.noConflict=function(){return typeof window!==h&&window.log===j&&(window.log=l),j},j});
|
||||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define(b):"object"==typeof module&&module.exports?module.exports=b():a.log=b()}(this,function(){"use strict";function a(a){return typeof console!==h&&(void 0!==console[a]?b(console,a):void 0!==console.log?b(console,"log"):g)}function b(a,b){var c=a[b];if("function"==typeof c.bind)return c.bind(a);try{return Function.prototype.bind.call(c,a)}catch(d){return function(){return Function.prototype.apply.apply(c,[a,arguments])}}}function c(a,b,c){return function(){typeof console!==h&&(d.call(this,b,c),this[a].apply(this,arguments))}}function d(a,b){for(var c=0;c<i.length;c++){var d=i[c];this[d]=c<a?g:this.methodFactory(d,a,b)}}function e(b,d,e){return a(b)||c.apply(this,arguments)}function f(a,b,c){function f(a){var b=(i[a]||"silent").toUpperCase();try{return void(window.localStorage[l]=b)}catch(c){}try{window.document.cookie=encodeURIComponent(l)+"="+b+";"}catch(c){}}function g(){var a;try{a=window.localStorage[l]}catch(b){}if(typeof a===h)try{var c=window.document.cookie,d=c.indexOf(encodeURIComponent(l)+"=");d&&(a=/^([^;]+)/.exec(c.slice(d))[1])}catch(b){}return void 0===k.levels[a]&&(a=void 0),a}var j,k=this,l="loglevel";a&&(l+=":"+a),k.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},k.methodFactory=c||e,k.getLevel=function(){return j},k.setLevel=function(b,c){if("string"==typeof b&&void 0!==k.levels[b.toUpperCase()]&&(b=k.levels[b.toUpperCase()]),!("number"==typeof b&&b>=0&&b<=k.levels.SILENT))throw"log.setLevel() called with invalid level: "+b;if(j=b,c!==!1&&f(b),d.call(k,b,a),typeof console===h&&b<k.levels.SILENT)return"No console available for logging"},k.setDefaultLevel=function(a){g()||k.setLevel(a,!1)},k.enableAll=function(a){k.setLevel(k.levels.TRACE,a)},k.disableAll=function(a){k.setLevel(k.levels.SILENT,a)};var m=g();null==m&&(m=null==b?"WARN":b),k.setLevel(m,!1)}var g=function(){},h="undefined",i=["trace","debug","info","warn","error"],j=new f,k={};j.getLogger=function(a){if("string"!=typeof a||""===a)throw new TypeError("You must supply a name when creating a logger.");var b=k[a];return b||(b=k[a]=new f(a,j.getLevel(),j.methodFactory)),b};var l=typeof window!==h?window.log:void 0;return j.noConflict=function(){return typeof window!==h&&window.log===j&&(window.log=l),j},j});
|
@ -1,6 +1,6 @@
|
||||
// The MIT License
|
||||
//
|
||||
// Copyright (c) 2014 Tom Perry
|
||||
// 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
|
||||
@ -25,29 +25,34 @@
|
||||
// Description of import into Moodle:
|
||||
// Download from https://github.com/pimterry/loglevel/releases
|
||||
// Copy loglevel.js into lib/amd/src/ in Moodle folder.
|
||||
// Add the license as a comment to the file and these instructions.
|
||||
// Add the jshint ignore:start and ignore:end comments.
|
||||
// Delete the jshint validthis:true comments.
|
||||
|
||||
/* jshint ignore:start */
|
||||
/*! loglevel - v1.4.0 - https://github.com/pimterry/loglevel - (c) 2015 Tim Perry - licensed MIT */
|
||||
/*
|
||||
* loglevel - https://github.com/pimterry/loglevel
|
||||
*
|
||||
* Copyright (c) 2013 Tim Perry
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
(function (root, definition) {
|
||||
"use strict";
|
||||
if (typeof module === 'object' && module.exports && typeof require === 'function') {
|
||||
module.exports = definition();
|
||||
} else if (typeof define === 'function' && typeof define.amd === 'object') {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(definition);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
module.exports = definition();
|
||||
} else {
|
||||
root.log = definition();
|
||||
}
|
||||
}(this, function () {
|
||||
"use strict";
|
||||
|
||||
// Slightly dubious tricks to cut down minimized file size
|
||||
var noop = function() {};
|
||||
var undefinedType = "undefined";
|
||||
|
||||
// Build the best logging method possible for this env
|
||||
// Wherever possible we want to bind, not wrap, to preserve stack traces
|
||||
function realMethod(methodName) {
|
||||
if (typeof console === undefinedType) {
|
||||
return false; // We can't build a real method without a console to log to
|
||||
return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
|
||||
} else if (console[methodName] !== undefined) {
|
||||
return bindMethod(console, methodName);
|
||||
} else if (console.log !== undefined) {
|
||||
@ -57,6 +62,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Cross-browser bind equivalent that works at least back to IE6
|
||||
function bindMethod(obj, methodName) {
|
||||
var method = obj[methodName];
|
||||
if (typeof method.bind === 'function') {
|
||||
@ -73,8 +79,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
// these private functions always need `this` to be set properly
|
||||
// These private functions always need `this` to be set properly
|
||||
|
||||
// In old IE versions, the console isn't present until you first open it.
|
||||
// We build realMethod() replacements here that regenerate logging methods
|
||||
function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
|
||||
return function () {
|
||||
if (typeof console !== undefinedType) {
|
||||
@ -85,6 +93,7 @@
|
||||
}
|
||||
|
||||
function replaceLoggingMethods(level, loggerName) {
|
||||
/*jshint validthis:true */
|
||||
for (var i = 0; i < logMethods.length; i++) {
|
||||
var methodName = logMethods[i];
|
||||
this[methodName] = (i < level) ?
|
||||
@ -93,9 +102,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// By default, we use closely bound real methods wherever possible, and
|
||||
// otherwise we wait for a console to appear, and then try again.
|
||||
function defaultMethodFactory(methodName, level, loggerName) {
|
||||
/*jshint validthis:true */
|
||||
return realMethod(methodName) ||
|
||||
enableLoggingWhenConsoleArrives.apply(this, arguments);
|
||||
enableLoggingWhenConsoleArrives.apply(this, arguments);
|
||||
}
|
||||
|
||||
var logMethods = [
|
||||
@ -107,113 +119,114 @@
|
||||
];
|
||||
|
||||
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();
|
||||
|
||||
// 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;
|
||||
|
||||
try {
|
||||
storedLevel = window.localStorage[storageKey];
|
||||
} catch (ignore) {}
|
||||
try {
|
||||
storedLevel = window.localStorage[storageKey];
|
||||
} catch (ignore) {}
|
||||
|
||||
if (typeof storedLevel === undefinedType) {
|
||||
try {
|
||||
var cookie = window.document.cookie;
|
||||
var location = cookie.indexOf(
|
||||
encodeURIComponent(storageKey) + "=");
|
||||
if (location) {
|
||||
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) {
|
||||
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 API
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Public logger API - see https://github.com/pimterry/loglevel for details
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Package-level API
|
||||
* Top-level API
|
||||
*
|
||||
*/
|
||||
|
||||
@ -222,13 +235,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;
|
||||
};
|
||||
@ -237,7 +250,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;
|
||||
}
|
||||
|
||||
@ -246,4 +259,3 @@
|
||||
|
||||
return defaultLogger;
|
||||
}));
|
||||
/* jshint ignore:end */
|
||||
|
@ -221,7 +221,7 @@
|
||||
<location>amd/src/loglevel.js</location>
|
||||
<name>loglevel.js</name>
|
||||
<license>MIT</license>
|
||||
<version>1.4.0</version>
|
||||
<version>1.4.1</version>
|
||||
</library>
|
||||
<library>
|
||||
<location>mustache</location>
|
||||
|
Loading…
x
Reference in New Issue
Block a user