loglevel
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "loglevel", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "dist/loglevel.min.js", | ||
@@ -5,0 +5,0 @@ "dependencies": {}, |
@@ -0,0 +0,0 @@ Filing tickets against loglevel |
@@ -1,203 +0,200 @@ | ||
/*! loglevel - v1.0.0 - https://github.com/pimterry/loglevel - (c) 2014 Tim Perry - licensed MIT */ | ||
;(function (undefined) { | ||
/*! loglevel - v1.1.0 - https://github.com/pimterry/loglevel - (c) 2014 Tim Perry - licensed MIT */ | ||
(function (root, definition) { | ||
if (typeof module === 'object' && module.exports && typeof require === 'function') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
root.log = definition(); | ||
} | ||
}(this, function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
var undefinedType = "undefined"; | ||
(function (name, definition) { | ||
if (typeof module === 'object' && module.exports && typeof require === 'function') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
if (console.log !== undefined) { | ||
return boundToConsole(console, 'log'); | ||
} else { | ||
return noop; | ||
} | ||
} else { | ||
this[name] = definition(); | ||
return boundToConsole(console, methodName); | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
} | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
if (console.log !== undefined) { | ||
return boundToConsole(console, 'log'); | ||
} else { | ||
return noop; | ||
} | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
return functionBindingWrapper(method, console); | ||
} else { | ||
return boundToConsole(console, methodName); | ||
} | ||
} | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
try { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} catch (e) { | ||
// In IE8 + Modernizr, the bind shim will reject the above, so we fall back to wrapping | ||
return functionBindingWrapper(method, console); | ||
} else { | ||
try { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} catch (e) { | ||
// In IE8 + Modernizr, the bind shim will reject the above, so we fall back to wrapping | ||
return functionBindingWrapper(method, console); | ||
} | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
function functionBindingWrapper(f, context) { | ||
return function() { | ||
Function.prototype.apply.apply(f, [context, arguments]); | ||
}; | ||
} | ||
function functionBindingWrapper(f, context) { | ||
return function() { | ||
Function.prototype.apply.apply(f, [context, arguments]); | ||
}; | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function replaceLoggingMethods(methodFactory) { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = methodFactory(logMethods[ii]); | ||
} | ||
function replaceLoggingMethods(methodFactory) { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = methodFactory(logMethods[ii]); | ||
} | ||
} | ||
function cookiesAvailable() { | ||
function cookiesAvailable() { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
} | ||
function localStorageAvailable() { | ||
try { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
window.localStorage !== undefined && | ||
window.localStorage !== null); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function localStorageAvailable() { | ||
try { | ||
return (typeof window !== undefinedType && | ||
window.localStorage !== undefined && | ||
window.localStorage !== null); | ||
} catch (e) { | ||
return false; | ||
function persistLevelIfPossible(levelNum) { | ||
var localStorageFail = false, | ||
levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
function persistLevelIfPossible(levelNum) { | ||
var localStorageFail = false, | ||
levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
if (localStorageAvailable()) { | ||
/* | ||
* Setting localStorage can create a DOM 22 Exception if running in Private mode | ||
* in Safari, so even if it is available we need to catch any errors when trying | ||
* to write to it | ||
*/ | ||
try { | ||
window.localStorage['loglevel'] = levelName; | ||
} catch (e) { | ||
localStorageFail = true; | ||
} | ||
} else { | ||
if (localStorageAvailable()) { | ||
/* | ||
* Setting localStorage can create a DOM 22 Exception if running in Private mode | ||
* in Safari, so even if it is available we need to catch any errors when trying | ||
* to write to it | ||
*/ | ||
try { | ||
window.localStorage['loglevel'] = levelName; | ||
} catch (e) { | ||
localStorageFail = true; | ||
} | ||
} else { | ||
localStorageFail = true; | ||
} | ||
if (localStorageFail && cookiesAvailable()) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
if (localStorageFail && cookiesAvailable()) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
} | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
function loadPersistedLevel() { | ||
var storedLevel; | ||
function loadPersistedLevel() { | ||
var storedLevel; | ||
if (localStorageAvailable()) { | ||
storedLevel = window.localStorage['loglevel']; | ||
} | ||
if (localStorageAvailable()) { | ||
storedLevel = window.localStorage['loglevel']; | ||
} | ||
if (storedLevel === undefined && cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
storedLevel = cookieMatch[1]; | ||
} | ||
if (self.levels[storedLevel] === undefined) { | ||
storedLevel = "WARN"; | ||
} | ||
self.setLevel(self.levels[storedLevel]); | ||
if (storedLevel === undefined && cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
storedLevel = cookieMatch[1]; | ||
} | ||
if (self.levels[storedLevel] === undefined) { | ||
storedLevel = "WARN"; | ||
} | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
self.setLevel(self.levels[storedLevel]); | ||
} | ||
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3, | ||
"ERROR": 4, "SILENT": 5}; | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
persistLevelIfPossible(level); | ||
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3, | ||
"ERROR": 4, "SILENT": 5}; | ||
if (level === self.levels.SILENT) { | ||
replaceLoggingMethods(function () { | ||
return noop; | ||
}); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
replaceLoggingMethods(function (methodName) { | ||
return function () { | ||
if (typeof console !== undefinedType) { | ||
self.setLevel(level); | ||
self[methodName].apply(self, arguments); | ||
} | ||
}; | ||
}); | ||
return "No console available for logging"; | ||
} else { | ||
replaceLoggingMethods(function (methodName) { | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
return realMethod(methodName); | ||
} else { | ||
return noop; | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
persistLevelIfPossible(level); | ||
if (level === self.levels.SILENT) { | ||
replaceLoggingMethods(function () { | ||
return noop; | ||
}); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
replaceLoggingMethods(function (methodName) { | ||
return function () { | ||
if (typeof console !== undefinedType) { | ||
self.setLevel(level); | ||
self[methodName].apply(self, arguments); | ||
} | ||
}); | ||
} | ||
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
}; | ||
}); | ||
return "No console available for logging"; | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
replaceLoggingMethods(function (methodName) { | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
return realMethod(methodName); | ||
} else { | ||
return noop; | ||
} | ||
}); | ||
} | ||
}; | ||
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
} | ||
}; | ||
self.enableAll = function() { | ||
self.setLevel(self.levels.TRACE); | ||
}; | ||
self.enableAll = function() { | ||
self.setLevel(self.levels.TRACE); | ||
}; | ||
self.disableAll = function() { | ||
self.setLevel(self.levels.SILENT); | ||
}; | ||
self.disableAll = function() { | ||
self.setLevel(self.levels.SILENT); | ||
}; | ||
// Grab the current global log variable in case of overwrite | ||
var _log = (typeof window !== undefinedType) ? window.log : undefined; | ||
self.noConflict = function() { | ||
if (typeof window !== undefinedType && | ||
window.log === self) { | ||
window.log = _log; | ||
} | ||
// Grab the current global log variable in case of overwrite | ||
var _log = (typeof window !== undefinedType) ? window.log : undefined; | ||
self.noConflict = function() { | ||
if (typeof window !== undefinedType && | ||
window.log === self) { | ||
window.log = _log; | ||
} | ||
return self; | ||
}; | ||
return self; | ||
}; | ||
loadPersistedLevel(); | ||
return self; | ||
})); | ||
})(); | ||
loadPersistedLevel(); | ||
return self; | ||
})); |
@@ -1,2 +0,2 @@ | ||
/*! loglevel - v1.0.0 - https://github.com/pimterry/loglevel - (c) 2014 Tim Perry - licensed MIT */ | ||
!function(a){var b="undefined";!function(a,b){"object"==typeof module&&module.exports&&"function"==typeof require?module.exports=b():"function"==typeof define&&"object"==typeof define.amd?define(b):this[a]=b()}("log",function(){function c(c){return typeof console===b?l:console[c]===a?console.log!==a?d(console,"log"):l:d(console,c)}function d(b,c){var d=b[c];if(d.bind!==a)return b[c].bind(b);if(Function.prototype.bind===a)return e(d,b);try{return Function.prototype.bind.call(b[c],b)}catch(f){return e(d,b)}}function e(a,b){return function(){Function.prototype.apply.apply(a,[b,arguments])}}function f(a){for(var b=0;b<m.length;b++)k[m[b]]=a(m[b])}function g(){return typeof window!==b&&window.document!==a&&window.document.cookie!==a}function h(){try{return typeof window!==b&&window.localStorage!==a&&null!==window.localStorage}catch(c){return!1}}function i(a){var b,c=!1;for(var d in k.levels)if(k.levels.hasOwnProperty(d)&&k.levels[d]===a){b=d;break}if(h())try{window.localStorage.loglevel=b}catch(e){c=!0}else c=!0;c&&g()&&(window.document.cookie="loglevel="+b+";")}function j(){var b;if(h()&&(b=window.localStorage.loglevel),b===a&&g()){var c=n.exec(window.document.cookie)||[];b=c[1]}k.levels[b]===a&&(b="WARN"),k.setLevel(k.levels[b])}var k={},l=function(){},m=["trace","debug","info","warn","error"],n=/loglevel=([^;]+)/;k.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},k.setLevel=function(d){if("number"==typeof d&&d>=0&&d<=k.levels.SILENT){if(i(d),d===k.levels.SILENT)return void f(function(){return l});if(typeof console===b)return f(function(a){return function(){typeof console!==b&&(k.setLevel(d),k[a].apply(k,arguments))}}),"No console available for logging";f(function(a){return d<=k.levels[a.toUpperCase()]?c(a):l})}else{if("string"!=typeof d||k.levels[d.toUpperCase()]===a)throw"log.setLevel() called with invalid level: "+d;k.setLevel(k.levels[d.toUpperCase()])}},k.enableAll=function(){k.setLevel(k.levels.TRACE)},k.disableAll=function(){k.setLevel(k.levels.SILENT)};var o=typeof window!==b?window.log:a;return k.noConflict=function(){return typeof window!==b&&window.log===k&&(window.log=o),k},j(),k})}(); | ||
/*! loglevel - v1.1.0 - https://github.com/pimterry/loglevel - (c) 2014 Tim Perry - licensed MIT */ | ||
!function(a,b){"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(){function a(a){return typeof console===k?j:void 0===console[a]?void 0!==console.log?b(console,"log"):j:b(console,a)}function b(a,b){var d=a[b];if(void 0!==d.bind)return a[b].bind(a);if(void 0===Function.prototype.bind)return c(d,a);try{return Function.prototype.bind.call(a[b],a)}catch(e){return c(d,a)}}function c(a,b){return function(){Function.prototype.apply.apply(a,[b,arguments])}}function d(a){for(var b=0;b<l.length;b++)i[l[b]]=a(l[b])}function e(){return typeof window!==k&&void 0!==window.document&&void 0!==window.document.cookie}function f(){try{return typeof window!==k&&void 0!==window.localStorage&&null!==window.localStorage}catch(a){return!1}}function g(a){var b,c=!1;for(var d in i.levels)if(i.levels.hasOwnProperty(d)&&i.levels[d]===a){b=d;break}if(f())try{window.localStorage.loglevel=b}catch(g){c=!0}else c=!0;c&&e()&&(window.document.cookie="loglevel="+b+";")}function h(){var a;if(f()&&(a=window.localStorage.loglevel),void 0===a&&e()){var b=m.exec(window.document.cookie)||[];a=b[1]}void 0===i.levels[a]&&(a="WARN"),i.setLevel(i.levels[a])}var i={},j=function(){},k="undefined",l=["trace","debug","info","warn","error"],m=/loglevel=([^;]+)/;i.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},i.setLevel=function(b){if("number"==typeof b&&b>=0&&b<=i.levels.SILENT){if(g(b),b===i.levels.SILENT)return void d(function(){return j});if(typeof console===k)return d(function(a){return function(){typeof console!==k&&(i.setLevel(b),i[a].apply(i,arguments))}}),"No console available for logging";d(function(c){return b<=i.levels[c.toUpperCase()]?a(c):j})}else{if("string"!=typeof b||void 0===i.levels[b.toUpperCase()])throw"log.setLevel() called with invalid level: "+b;i.setLevel(i.levels[b.toUpperCase()])}},i.enableAll=function(){i.setLevel(i.levels.TRACE)},i.disableAll=function(){i.setLevel(i.levels.SILENT)};var n=typeof window!==k?window.log:void 0;return i.noConflict=function(){return typeof window!==k&&window.log===i&&(window.log=n),i},h(),i}); |
@@ -50,2 +50,9 @@ 'use strict'; | ||
}, | ||
context: { | ||
src: 'test/test-context-using-apply.test.js', | ||
options: { | ||
specs: 'test/global-integration-with-new-context.js', | ||
vendor: 'test/vendor/*.js' | ||
} | ||
}, | ||
withCoverage: { | ||
@@ -178,2 +185,11 @@ src: 'lib/**/*.js', | ||
all: ['test/*-qunit.html'] | ||
}, | ||
preprocess: { | ||
"test-context-using-apply": { | ||
src: 'test/test-context-using-apply.js', | ||
dest: 'test/test-context-using-apply.test.js' | ||
} | ||
}, | ||
clean:{ | ||
test:['test/test-context-using-apply.test.js'] | ||
} | ||
@@ -195,2 +211,4 @@ }); | ||
grunt.loadNpmTasks('grunt-saucelabs'); | ||
grunt.loadNpmTasks('grunt-preprocess'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
@@ -201,3 +219,3 @@ // Build a distributable release | ||
// Check everything is good | ||
grunt.registerTask('test', ['jshint', 'jasmine:requirejs', 'jasmine:global', 'jasmine_node', 'jasmine:withCoverage', 'qunit']); | ||
grunt.registerTask('test', ['jshint', 'jasmine:requirejs', 'jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine_node', 'jasmine:withCoverage', 'qunit']); | ||
@@ -204,0 +222,0 @@ // Test with a live server and an actual browser |
/* | ||
* loglevel - https://github.com/pimterry/loglevel | ||
* | ||
* Copyright (c) 2013 Tim Perry | ||
* Licensed under the MIT license. | ||
*/ | ||
;(function (undefined) { | ||
* loglevel - https://github.com/pimterry/loglevel | ||
* | ||
* Copyright (c) 2013 Tim Perry | ||
* Licensed under the MIT license. | ||
*/ | ||
(function (root, definition) { | ||
if (typeof module === 'object' && module.exports && typeof require === 'function') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
root.log = definition(); | ||
} | ||
}(this, function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
var undefinedType = "undefined"; | ||
(function (name, definition) { | ||
if (typeof module === 'object' && module.exports && typeof require === 'function') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
if (console.log !== undefined) { | ||
return boundToConsole(console, 'log'); | ||
} else { | ||
return noop; | ||
} | ||
} else { | ||
this[name] = definition(); | ||
return boundToConsole(console, methodName); | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
} | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
if (console.log !== undefined) { | ||
return boundToConsole(console, 'log'); | ||
} else { | ||
return noop; | ||
} | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
return functionBindingWrapper(method, console); | ||
} else { | ||
return boundToConsole(console, methodName); | ||
} | ||
} | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
try { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} catch (e) { | ||
// In IE8 + Modernizr, the bind shim will reject the above, so we fall back to wrapping | ||
return functionBindingWrapper(method, console); | ||
} else { | ||
try { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} catch (e) { | ||
// In IE8 + Modernizr, the bind shim will reject the above, so we fall back to wrapping | ||
return functionBindingWrapper(method, console); | ||
} | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
function functionBindingWrapper(f, context) { | ||
return function() { | ||
Function.prototype.apply.apply(f, [context, arguments]); | ||
}; | ||
} | ||
function functionBindingWrapper(f, context) { | ||
return function() { | ||
Function.prototype.apply.apply(f, [context, arguments]); | ||
}; | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function replaceLoggingMethods(methodFactory) { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = methodFactory(logMethods[ii]); | ||
} | ||
function replaceLoggingMethods(methodFactory) { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = methodFactory(logMethods[ii]); | ||
} | ||
} | ||
function cookiesAvailable() { | ||
function cookiesAvailable() { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
} | ||
function localStorageAvailable() { | ||
try { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
window.localStorage !== undefined && | ||
window.localStorage !== null); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function localStorageAvailable() { | ||
try { | ||
return (typeof window !== undefinedType && | ||
window.localStorage !== undefined && | ||
window.localStorage !== null); | ||
} catch (e) { | ||
return false; | ||
function persistLevelIfPossible(levelNum) { | ||
var localStorageFail = false, | ||
levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
function persistLevelIfPossible(levelNum) { | ||
var localStorageFail = false, | ||
levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
if (localStorageAvailable()) { | ||
/* | ||
* Setting localStorage can create a DOM 22 Exception if running in Private mode | ||
* in Safari, so even if it is available we need to catch any errors when trying | ||
* to write to it | ||
*/ | ||
try { | ||
window.localStorage['loglevel'] = levelName; | ||
} catch (e) { | ||
localStorageFail = true; | ||
} | ||
} else { | ||
if (localStorageAvailable()) { | ||
/* | ||
* Setting localStorage can create a DOM 22 Exception if running in Private mode | ||
* in Safari, so even if it is available we need to catch any errors when trying | ||
* to write to it | ||
*/ | ||
try { | ||
window.localStorage['loglevel'] = levelName; | ||
} catch (e) { | ||
localStorageFail = true; | ||
} | ||
} else { | ||
localStorageFail = true; | ||
} | ||
if (localStorageFail && cookiesAvailable()) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
if (localStorageFail && cookiesAvailable()) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
} | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
function loadPersistedLevel() { | ||
var storedLevel; | ||
function loadPersistedLevel() { | ||
var storedLevel; | ||
if (localStorageAvailable()) { | ||
storedLevel = window.localStorage['loglevel']; | ||
} | ||
if (localStorageAvailable()) { | ||
storedLevel = window.localStorage['loglevel']; | ||
} | ||
if (storedLevel === undefined && cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
storedLevel = cookieMatch[1]; | ||
} | ||
if (self.levels[storedLevel] === undefined) { | ||
storedLevel = "WARN"; | ||
} | ||
self.setLevel(self.levels[storedLevel]); | ||
if (storedLevel === undefined && cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
storedLevel = cookieMatch[1]; | ||
} | ||
if (self.levels[storedLevel] === undefined) { | ||
storedLevel = "WARN"; | ||
} | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
self.setLevel(self.levels[storedLevel]); | ||
} | ||
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3, | ||
"ERROR": 4, "SILENT": 5}; | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
persistLevelIfPossible(level); | ||
self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3, | ||
"ERROR": 4, "SILENT": 5}; | ||
if (level === self.levels.SILENT) { | ||
replaceLoggingMethods(function () { | ||
return noop; | ||
}); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
replaceLoggingMethods(function (methodName) { | ||
return function () { | ||
if (typeof console !== undefinedType) { | ||
self.setLevel(level); | ||
self[methodName].apply(self, arguments); | ||
} | ||
}; | ||
}); | ||
return "No console available for logging"; | ||
} else { | ||
replaceLoggingMethods(function (methodName) { | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
return realMethod(methodName); | ||
} else { | ||
return noop; | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
persistLevelIfPossible(level); | ||
if (level === self.levels.SILENT) { | ||
replaceLoggingMethods(function () { | ||
return noop; | ||
}); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
replaceLoggingMethods(function (methodName) { | ||
return function () { | ||
if (typeof console !== undefinedType) { | ||
self.setLevel(level); | ||
self[methodName].apply(self, arguments); | ||
} | ||
}); | ||
} | ||
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
}; | ||
}); | ||
return "No console available for logging"; | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
replaceLoggingMethods(function (methodName) { | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
return realMethod(methodName); | ||
} else { | ||
return noop; | ||
} | ||
}); | ||
} | ||
}; | ||
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
} | ||
}; | ||
self.enableAll = function() { | ||
self.setLevel(self.levels.TRACE); | ||
}; | ||
self.enableAll = function() { | ||
self.setLevel(self.levels.TRACE); | ||
}; | ||
self.disableAll = function() { | ||
self.setLevel(self.levels.SILENT); | ||
}; | ||
self.disableAll = function() { | ||
self.setLevel(self.levels.SILENT); | ||
}; | ||
// Grab the current global log variable in case of overwrite | ||
var _log = (typeof window !== undefinedType) ? window.log : undefined; | ||
self.noConflict = function() { | ||
if (typeof window !== undefinedType && | ||
window.log === self) { | ||
window.log = _log; | ||
} | ||
// Grab the current global log variable in case of overwrite | ||
var _log = (typeof window !== undefinedType) ? window.log : undefined; | ||
self.noConflict = function() { | ||
if (typeof window !== undefinedType && | ||
window.log === self) { | ||
window.log = _log; | ||
} | ||
return self; | ||
}; | ||
return self; | ||
}; | ||
loadPersistedLevel(); | ||
return self; | ||
})); | ||
})(); | ||
loadPersistedLevel(); | ||
return self; | ||
})); |
{ | ||
"name": "loglevel", | ||
"description": "Minimal lightweight logging for JavaScript, adding reliable log level methods to any available console.log methods", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/pimterry/loglevel", | ||
@@ -49,3 +49,5 @@ "author": { | ||
"grunt-contrib-qunit": "~0.5.2", | ||
"qunitjs": "^1.14.0" | ||
"grunt-preprocess": "^4.0.0", | ||
"grunt-contrib-clean": "^0.6.0", | ||
"qunitjs": "1.14.0" | ||
}, | ||
@@ -52,0 +54,0 @@ "jam": { |
@@ -34,3 +34,3 @@ # loglevel [![Build Status](https://travis-ci.org/pimterry/loglevel.png)](https://travis-ci.org/pimterry/loglevel) [![Coverage Status](https://coveralls.io/repos/pimterry/loglevel/badge.png?branch=master)](https://coveralls.io/r/pimterry/loglevel?branch=master) [![Dependency status](https://david-dm.org/pimterry/loglevel/dev-status.png)](https://david-dm.org/pimterry/loglevel#info=devDependencies&view=table) | ||
Alternatively if you just want to grab the file yourself, you can download either the current stable [production version][min] or the [development version][max] directly, or reference it remotely on CDNJS at `//cdnjs.cloudflare.com/ajax/libs/loglevel/0.5.0/loglevel.min.js` | ||
Alternatively if you just want to grab the file yourself, you can download either the current stable [production version][min] or the [development version][max] directly, or reference it remotely on CDNJS at `//cdnjs.cloudflare.com/ajax/libs/loglevel/0.6.0/loglevel.min.js` | ||
@@ -153,4 +153,6 @@ Finally, if you want to tweak loglevel to your own needs or you immediately need the cutting-edge version, clone this repo and see [Developing & Contributing](#developing--contributing) below for build instructions. | ||
v1.0.0 - Official stable release. Fixed a bug with localStorage in Android webviews, improved CommonJS detection, and added noConflict(). | ||
v1.0.0 - Official stable release! Fixed a bug with localStorage in Android webviews, improved CommonJS detection, and added noConflict(). | ||
v1.1.0 - Added support for including loglevel with preprocessing and .apply() (#50), and fixed QUnit dep version which made tests potentially unstable. | ||
## License | ||
@@ -157,0 +159,0 @@ Copyright (c) 2013 Tim Perry |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /* global log */ |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /* |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
28
1738
161
93362
18