loglevel
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "loglevel", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main": "dist/loglevel.min.js", | ||
@@ -5,0 +5,0 @@ "dependencies": {}, |
@@ -1,144 +0,146 @@ | ||
/*! loglevel - v0.2.0 - 2013-06-19 | ||
* https://github.com/pimterry/loglevel | ||
* Copyright (c) 2013 Tim Perry; Licensed MIT */ | ||
(function (name, definition) { | ||
if (typeof module !== 'undefined') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
this[name] = definition(); | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
function realMethod(methodName) { | ||
if (typeof console === "undefined") { | ||
return noop; | ||
} else if (typeof console[methodName] === "undefined") { | ||
return boundToConsole(console, 'log') || noop; | ||
/*! loglevel - v0.3.1 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */ | ||
;(function (undefined) { | ||
var undefinedType = "undefined"; | ||
(function (name, definition) { | ||
if (typeof module !== 'undefined') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
return boundToConsole(console, methodName); | ||
this[name] = definition(); | ||
} | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (typeof method.bind === "undefined") { | ||
if (typeof Function.prototype.bind === "undefined") { | ||
return function() { | ||
method.apply(console, arguments); | ||
}; | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
return boundToConsole(console, 'log') || noop; | ||
} else { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
return boundToConsole(console, methodName); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function clearMethods() { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = noop; | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
return function() { | ||
method.apply(console, arguments); | ||
}; | ||
} else { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
} | ||
function cookiesAvailable() { | ||
return (typeof window !== "undefined" && | ||
typeof window.document !== "undefined" && | ||
typeof window.document.cookie !== "undefined"); | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function setLevelInCookie(levelNum) { | ||
if (!cookiesAvailable()) { | ||
return; | ||
function clearMethods() { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = noop; | ||
} | ||
} | ||
var levelName; | ||
function cookiesAvailable() { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
} | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
function setLevelInCookie(levelNum) { | ||
if (!cookiesAvailable()) { | ||
return; | ||
} | ||
} | ||
if (levelName !== undefined) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
var levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
if (levelName !== undefined) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
} | ||
} | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
function loadLevelFromCookie() { | ||
var cookieLevel; | ||
function loadLevelFromCookie() { | ||
var cookieLevel; | ||
if (cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
cookieLevel = cookieMatch[1]; | ||
if (cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
cookieLevel = cookieMatch[1]; | ||
} | ||
self.setLevel(self.levels[cookieLevel] || self.levels.WARN); | ||
} | ||
self.setLevel(self.levels[cookieLevel] || self.levels.WARN); | ||
} | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
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.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
setLevelInCookie(level); | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
setLevelInCookie(level); | ||
if (level === self.levels.SILENT) { | ||
clearMethods(); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
clearMethods(); | ||
throw "No console available for logging"; | ||
} else { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
var methodName = logMethods[ii]; | ||
if (level === self.levels.SILENT) { | ||
clearMethods(); | ||
return; | ||
} else if (typeof console === "undefined") { | ||
clearMethods(); | ||
throw "No console available for logging"; | ||
} else { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
var methodName = logMethods[ii]; | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
self[methodName] = realMethod(methodName); | ||
} else { | ||
self[methodName] = noop; | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
self[methodName] = realMethod(methodName); | ||
} else { | ||
self[methodName] = noop; | ||
} | ||
} | ||
} | ||
} else if (typeof level === "string") { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
} | ||
} else if (typeof level === "string") { | ||
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); | ||
}; | ||
try { | ||
loadLevelFromCookie(); | ||
} catch (e) { | ||
self.setLevel(self.levels.SILENT); | ||
} | ||
return self; | ||
})); | ||
try { | ||
loadLevelFromCookie(); | ||
} catch (e) { | ||
self.setLevel(self.levels.SILENT); | ||
} | ||
return self; | ||
})); | ||
})(); |
@@ -1,4 +0,2 @@ | ||
/*! loglevel - v0.2.0 - 2013-06-19 | ||
* https://github.com/pimterry/loglevel | ||
* Copyright (c) 2013 Tim Perry; Licensed MIT */ | ||
(function(e,o){"undefined"!=typeof module?module.exports=o():"function"==typeof define&&"object"==typeof define.amd?define(o):this[e]=o()})("log",function(){function e(e){return"undefined"==typeof console?f:console[e]===void 0?o(console,"log")||f:o(console,e)}function o(e,o){var n=e[o];return n.bind===void 0?Function.prototype.bind===void 0?function(){n.apply(e,arguments)}:Function.prototype.bind.call(e[o],e):e[o].bind(e)}function n(){for(var e=0;v.length>e;e++)r[v[e]]=f}function l(){return"undefined"!=typeof window&&window.document!==void 0&&window.document.cookie!==void 0}function t(e){if(l()){var o;for(var n in r.levels)if(r.levels.hasOwnProperty(n)&&r.levels[n]===e){o=n;break}void 0!==o&&(window.document.cookie="loglevel="+o+";")}}function i(){var e;if(l()){var o=d.exec(window.document.cookie)||[];e=o[1]}r.setLevel(r.levels[e]||r.levels.WARN)}var r={},f=function(){},v=["trace","debug","info","warn","error"],d=/loglevel=([^;]+)/;r.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},r.setLevel=function(o){if("number"==typeof o&&o>=0&&r.levels.SILENT>=o){if(t(o),o===r.levels.SILENT)return n(),void 0;if("undefined"==typeof console)throw n(),"No console available for logging";for(var l=0;v.length>l;l++){var i=v[l];r[i]=r.levels[i.toUpperCase()]>=o?e(i):f}}else{if("string"!=typeof o)throw"log.setLevel() called with invalid level: "+o;r.setLevel(r.levels[o.toUpperCase()])}},r.enableAll=function(){r.setLevel(r.levels.TRACE)},r.disableAll=function(){r.setLevel(r.levels.SILENT)};try{i()}catch(c){r.setLevel(r.levels.SILENT)}return r}); | ||
/*! loglevel - v0.3.1 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */ | ||
(function(e){var o="undefined";(function(e,o){"undefined"!=typeof module?module.exports=o():"function"==typeof define&&"object"==typeof define.amd?define(o):this[e]=o()})("log",function(){function n(n){return typeof console===o?s:console[n]===e?l(console,"log")||s:l(console,n)}function l(o,n){var l=o[n];return l.bind===e?Function.prototype.bind===e?function(){l.apply(o,arguments)}:Function.prototype.bind.call(o[n],o):o[n].bind(o)}function t(){for(var e=0;v.length>e;e++)c[v[e]]=s}function i(){return typeof window!==o&&window.document!==e&&window.document.cookie!==e}function r(o){if(i()){var n;for(var l in c.levels)if(c.levels.hasOwnProperty(l)&&c.levels[l]===o){n=l;break}n!==e&&(window.document.cookie="loglevel="+n+";")}}function f(){var e;if(i()){var o=u.exec(window.document.cookie)||[];e=o[1]}c.setLevel(c.levels[e]||c.levels.WARN)}var c={},s=function(){},v=["trace","debug","info","warn","error"],u=/loglevel=([^;]+)/;c.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},c.setLevel=function(l){if("number"==typeof l&&l>=0&&c.levels.SILENT>=l){if(r(l),l===c.levels.SILENT)return t(),e;if(typeof console===o)throw t(),"No console available for logging";for(var i=0;v.length>i;i++){var f=v[i];c[f]=c.levels[f.toUpperCase()]>=l?n(f):s}}else{if("string"!=typeof l)throw"log.setLevel() called with invalid level: "+l;c.setLevel(c.levels[l.toUpperCase()])}},c.enableAll=function(){c.setLevel(c.levels.TRACE)},c.disableAll=function(){c.setLevel(c.levels.SILENT)};try{f()}catch(a){c.setLevel(c.levels.SILENT)}return c})})(); |
@@ -9,7 +9,6 @@ 'use strict'; | ||
pkg: grunt.file.readJSON('package.json'), | ||
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + | ||
'<%= grunt.template.today("yyyy-mm-dd") %>\n' + | ||
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + | ||
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + | ||
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', | ||
banner: '/*! <%= pkg.name %> - v<%= pkg.version %>' + | ||
' - <%= pkg.homepage %>' + | ||
' - (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' + | ||
' - licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', | ||
// Task configuration. | ||
@@ -16,0 +15,0 @@ concat: { |
@@ -8,142 +8,146 @@ /* | ||
(function (name, definition) { | ||
if (typeof module !== 'undefined') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
this[name] = definition(); | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
function realMethod(methodName) { | ||
if (typeof console === "undefined") { | ||
return noop; | ||
} else if (typeof console[methodName] === "undefined") { | ||
return boundToConsole(console, 'log') || noop; | ||
;(function (undefined) { | ||
var undefinedType = "undefined"; | ||
(function (name, definition) { | ||
if (typeof module !== 'undefined') { | ||
module.exports = definition(); | ||
} else if (typeof define === 'function' && typeof define.amd === 'object') { | ||
define(definition); | ||
} else { | ||
return boundToConsole(console, methodName); | ||
this[name] = definition(); | ||
} | ||
} | ||
}('log', function () { | ||
var self = {}; | ||
var noop = function() {}; | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (typeof method.bind === "undefined") { | ||
if (typeof Function.prototype.bind === "undefined") { | ||
return function() { | ||
method.apply(console, arguments); | ||
}; | ||
function realMethod(methodName) { | ||
if (typeof console === undefinedType) { | ||
return noop; | ||
} else if (console[methodName] === undefined) { | ||
return boundToConsole(console, 'log') || noop; | ||
} else { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
return boundToConsole(console, methodName); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function clearMethods() { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = noop; | ||
function boundToConsole(console, methodName) { | ||
var method = console[methodName]; | ||
if (method.bind === undefined) { | ||
if (Function.prototype.bind === undefined) { | ||
return function() { | ||
method.apply(console, arguments); | ||
}; | ||
} else { | ||
return Function.prototype.bind.call(console[methodName], console); | ||
} | ||
} else { | ||
return console[methodName].bind(console); | ||
} | ||
} | ||
} | ||
function cookiesAvailable() { | ||
return (typeof window !== "undefined" && | ||
typeof window.document !== "undefined" && | ||
typeof window.document.cookie !== "undefined"); | ||
} | ||
var logMethods = [ | ||
"trace", | ||
"debug", | ||
"info", | ||
"warn", | ||
"error" | ||
]; | ||
function setLevelInCookie(levelNum) { | ||
if (!cookiesAvailable()) { | ||
return; | ||
function clearMethods() { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
self[logMethods[ii]] = noop; | ||
} | ||
} | ||
var levelName; | ||
function cookiesAvailable() { | ||
return (typeof window !== undefinedType && | ||
window.document !== undefined && | ||
window.document.cookie !== undefined); | ||
} | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
function setLevelInCookie(levelNum) { | ||
if (!cookiesAvailable()) { | ||
return; | ||
} | ||
} | ||
if (levelName !== undefined) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
var levelName; | ||
for (var key in self.levels) { | ||
if (self.levels.hasOwnProperty(key) && self.levels[key] === levelNum) { | ||
levelName = key; | ||
break; | ||
} | ||
} | ||
if (levelName !== undefined) { | ||
window.document.cookie = "loglevel=" + levelName + ";"; | ||
} | ||
} | ||
} | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
var cookieRegex = /loglevel=([^;]+)/; | ||
function loadLevelFromCookie() { | ||
var cookieLevel; | ||
function loadLevelFromCookie() { | ||
var cookieLevel; | ||
if (cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
cookieLevel = cookieMatch[1]; | ||
if (cookiesAvailable()) { | ||
var cookieMatch = cookieRegex.exec(window.document.cookie) || []; | ||
cookieLevel = cookieMatch[1]; | ||
} | ||
self.setLevel(self.levels[cookieLevel] || self.levels.WARN); | ||
} | ||
self.setLevel(self.levels[cookieLevel] || self.levels.WARN); | ||
} | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
/* | ||
* | ||
* Public API | ||
* | ||
*/ | ||
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.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
setLevelInCookie(level); | ||
self.setLevel = function (level) { | ||
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) { | ||
setLevelInCookie(level); | ||
if (level === self.levels.SILENT) { | ||
clearMethods(); | ||
return; | ||
} else if (typeof console === undefinedType) { | ||
clearMethods(); | ||
throw "No console available for logging"; | ||
} else { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
var methodName = logMethods[ii]; | ||
if (level === self.levels.SILENT) { | ||
clearMethods(); | ||
return; | ||
} else if (typeof console === "undefined") { | ||
clearMethods(); | ||
throw "No console available for logging"; | ||
} else { | ||
for (var ii = 0; ii < logMethods.length; ii++) { | ||
var methodName = logMethods[ii]; | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
self[methodName] = realMethod(methodName); | ||
} else { | ||
self[methodName] = noop; | ||
if (level <= self.levels[methodName.toUpperCase()]) { | ||
self[methodName] = realMethod(methodName); | ||
} else { | ||
self[methodName] = noop; | ||
} | ||
} | ||
} | ||
} else if (typeof level === "string") { | ||
self.setLevel(self.levels[level.toUpperCase()]); | ||
} else { | ||
throw "log.setLevel() called with invalid level: " + level; | ||
} | ||
} else if (typeof level === "string") { | ||
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); | ||
}; | ||
try { | ||
loadLevelFromCookie(); | ||
} catch (e) { | ||
self.setLevel(self.levels.SILENT); | ||
} | ||
return self; | ||
})); | ||
try { | ||
loadLevelFromCookie(); | ||
} catch (e) { | ||
self.setLevel(self.levels.SILENT); | ||
} | ||
return self; | ||
})); | ||
})(); |
{ | ||
"name": "loglevel", | ||
"description": "Minimal lightweight logging for JavaScript, adding reliable log level methods to any available console.log methods", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "https://github.com/pimterry/loglevel", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -28,6 +28,8 @@ # loglevel [![Build Status](https://travis-ci.org/pimterry/loglevel.png)](https://travis-ci.org/pimterry/loglevel) | ||
If you're using node, you can run `npm install loglevel`. loglevel is also available via [Bower](https://github.com/bower/bower) (run `bower install loglevel`) or [JamJS](http://jamjs.org/packages/#/details/loglevel) (run `jam install loglevel`) | ||
If you're using node, you can run `npm install loglevel`. | ||
Alternatively if you want to grab the file directly, you can download either the [production version][min] or the [development version][max] directly. | ||
loglevel is also available via [Bower](https://github.com/bower/bower) (`bower install loglevel`) or [JamJS](http://jamjs.org/packages/#/details/loglevel) (`jam install loglevel`) | ||
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. | ||
[min]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.min.js | ||
@@ -108,2 +110,4 @@ [max]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.js | ||
v0.3.1 - Fixed incorrect text in release build banner, various other minor tweaks | ||
## License | ||
@@ -113,2 +117,2 @@ Copyright (c) 2013 Tim Perry | ||
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/3393271900ddc6808ae1901f3760a59e "githalytics.com")](http://githalytics.com/pimterry/loglevel) | ||
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/3393271900ddc6808ae1901f3760a59e)](http://githalytics.com/pimterry/loglevel) |
"use strict"; | ||
define(['../lib/loglevel'], function(log) { | ||
describe("Integration smoke tests", function() { | ||
var describeIfConsoleAvailable = | ||
typeof console !== "undefined" ? describe : xdescribe; | ||
define(['../lib/loglevel', 'test/test-helpers'], function(log, testHelpers) { | ||
var describeIf = testHelpers.describeIf; | ||
var itIf = testHelpers.itIf; | ||
describeIfConsoleAvailable("log methods", function() { | ||
it("can all be called", function() { | ||
if (typeof console !== "undefined") { | ||
log.setLevel(log.levels.TRACE); | ||
} | ||
describe("Integration smoke tests:", function() { | ||
describe("log methods", function() { | ||
it("can all be disabled", function() { | ||
log.setLevel(log.levels.SILENT); | ||
log.trace("trace"); | ||
@@ -22,5 +19,8 @@ log.debug("debug"); | ||
describe("log methods", function() { | ||
it("can all be disabled", function() { | ||
log.setLevel(log.levels.SILENT); | ||
describeIf(typeof console !== "undefined", "log methods", function() { | ||
it("can all be called", function() { | ||
if (typeof console !== "undefined") { | ||
log.setLevel(log.levels.TRACE); | ||
} | ||
log.trace("trace"); | ||
@@ -34,3 +34,9 @@ log.debug("debug"); | ||
describeIfConsoleAvailable("log levels", function() { | ||
describeIf(typeof console !== "undefined", "log levels", function() { | ||
beforeEach(function() { | ||
this.addMatchers({ | ||
"toBeTheStoredLevel" : testHelpers.toBeTheStoredLevel | ||
}); | ||
}); | ||
it("are all settable", function() { | ||
@@ -44,20 +50,20 @@ log.setLevel(log.levels.TRACE); | ||
it("are saved in cookies", function() { | ||
itIf(testHelpers.isAnyLevelStoragePossible(), "are persisted", function() { | ||
log.setLevel(log.levels.TRACE); | ||
expect(window.document.cookie).toContain("loglevel=TRACE"); | ||
expect('trace').toBeTheStoredLevel(); | ||
log.setLevel(log.levels.DEBUG); | ||
expect(window.document.cookie).toContain("loglevel=DEBUG"); | ||
expect('debug').toBeTheStoredLevel(); | ||
log.setLevel(log.levels.INFO); | ||
expect(window.document.cookie).toContain("loglevel=INFO"); | ||
expect('info').toBeTheStoredLevel(); | ||
log.setLevel(log.levels.WARN); | ||
expect(window.document.cookie).toContain("loglevel=WARN"); | ||
expect('warn').toBeTheStoredLevel(); | ||
log.setLevel(log.levels.ERROR); | ||
expect(window.document.cookie).toContain("loglevel=ERROR"); | ||
expect('error').toBeTheStoredLevel(); | ||
log.setLevel(log.levels.SILENT); | ||
expect(window.document.cookie).toContain("loglevel=SILENT"); | ||
expect('silent').toBeTheStoredLevel(); | ||
}); | ||
@@ -64,0 +70,0 @@ }); |
@@ -14,3 +14,3 @@ "use strict"; | ||
describe("LogLevel fallback functionality", function() { | ||
describe("Fallback functionality:", function() { | ||
describe("with no console present", function() { | ||
@@ -17,0 +17,0 @@ beforeEach(function() { |
"use strict"; | ||
var originalConsole = window.console; | ||
var originalDocument = window.document; | ||
var originalCookie = window.document.cookie; | ||
define(['test/test-helpers'], function(testHelpers) { | ||
var describeIf = testHelpers.describeIf; | ||
var it = testHelpers.itWithFreshLog; | ||
function deleteLoglevelCookie() { | ||
window.document.cookie = "loglevel=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"; | ||
} | ||
var originalConsole = window.console; | ||
var originalDocument = window.document; | ||
define(['../lib/loglevel'], function(log) { | ||
var it = itWithFreshLog; | ||
describeIf(testHelpers.isCookieStorageAvailable(), "Cookie persistence tests:", function() { | ||
describe("Cookie tests", function() { | ||
beforeEach(function() { | ||
window.console = {"log" : jasmine.createSpy("console.log")}; | ||
this.addMatchers({ "toBeAtLevel" : toBeAtLevel }); | ||
this.addMatchers({ | ||
"toBeAtLevel" : testHelpers.toBeAtLevel, | ||
"toBeTheStoredLevel" : testHelpers.toBeTheLevelStoredByCookie | ||
}); | ||
}); | ||
@@ -23,8 +22,7 @@ | ||
window.console = originalConsole; | ||
window.document.cookie = originalCookie; | ||
}); | ||
describe("If cookie not set", function() { | ||
describe("If no level is saved", function() { | ||
beforeEach(function() { | ||
window.document.cookie = "loglevel=;"; | ||
testHelpers.clearStoredLevels(); | ||
}); | ||
@@ -36,2 +34,6 @@ | ||
it("warn is persisted as the current level", function(log) { | ||
expect("warn").toBeTheStoredLevel(); | ||
}); | ||
it("log can be set to info level", function(log) { | ||
@@ -42,11 +44,11 @@ log.setLevel("info"); | ||
it("log.setLevel sets a cookie with the given level", function(log) { | ||
it("log.setLevel() sets a cookie with the given level", function(log) { | ||
log.setLevel("debug"); | ||
expect(window.document.cookie).toContain("loglevel=DEBUG"); | ||
expect("debug").toBeTheStoredLevel(); | ||
}); | ||
}); | ||
describe("If cookie is set to info level", function() { | ||
describe("If info level is saved", function() { | ||
beforeEach(function() { | ||
window.document.cookie = "loglevel=INFO"; | ||
testHelpers.setStoredLevel("info"); | ||
}); | ||
@@ -63,10 +65,11 @@ | ||
it("changing the log level overwrites the cookie", function(log) { | ||
it("log.setLevel() overwrites the saved level", function(log) { | ||
log.setLevel("error"); | ||
expect(window.document.cookie).toContain("loglevel=ERROR"); | ||
expect(window.document.cookie).not.toContain("loglevel=INFO"); | ||
expect("error").toBeTheStoredLevel(); | ||
expect("info").not.toBeTheStoredLevel(); | ||
}); | ||
}); | ||
describe("If cookie is set to error level with other cookies", function() { | ||
describe("If the level is saved with other data", function() { | ||
beforeEach(function() { | ||
@@ -87,12 +90,13 @@ window.document.cookie = "qwe=asd"; | ||
it("log.setLevel() overrides the loglevel cookie only with the new level", function(log) { | ||
it("log.setLevel() overrides the saved level only", function(log) { | ||
log.setLevel("debug"); | ||
expect(window.document.cookie).toContain("loglevel=DEBUG"); | ||
expect(window.document.cookie).toContain("hello world"); | ||
expect('debug').toBeTheStoredLevel(); | ||
expect(window.document.cookie).toContain("msg=hello world"); | ||
}); | ||
}); | ||
describe("If cookie is set incorrectly", function() { | ||
describe("If the level cookie is set incorrectly", function() { | ||
beforeEach(function() { | ||
window.document.cookie = "loglevel=GIBBERISH"; | ||
testHelpers.setCookieStoredLevel('gibberish'); | ||
}); | ||
@@ -104,29 +108,6 @@ | ||
it("log can be changed to info level", function(log) { | ||
log.setLevel("info"); | ||
expect(log).toBeAtLevel("info"); | ||
it("warn is persisted as the current level, overriding the invalid cookie", function(log) { | ||
expect("warn").toBeTheStoredLevel(); | ||
}); | ||
it("log.setLevel() overrides the cookie with the new level", function(log) { | ||
log.setLevel("debug"); | ||
expect(window.document.cookie).toContain("loglevel=DEBUG"); | ||
}); | ||
}); | ||
describe("If document.cookie doesn't exist", function() { | ||
window.document.cookie = undefined; | ||
if (typeof window.document.cookie !== "undefined") { | ||
return; | ||
} else { | ||
window.document.cookie = originalCookie; | ||
} | ||
beforeEach(function() { | ||
window.document.cookie = undefined; | ||
}); | ||
it("warn is the default log level", function(log) { | ||
expect(log).toBeAtLevel("warn"); | ||
}); | ||
it("log can be changed to info level", function(log) { | ||
@@ -137,38 +118,11 @@ log.setLevel("info"); | ||
it("log.setLevel() does nothing with cookies when the level is changed", function(log) { | ||
log.setLevel("trace"); | ||
expect(window.document.cookie).not.toBeDefined(); | ||
}); | ||
}); | ||
it("log.setLevel() overrides the saved level with the new level", function(log) { | ||
expect('debug').not.toBeTheStoredLevel(); | ||
describe("If window.document doesn't exist", function() { | ||
try { | ||
window.document = undefined; | ||
if (window.document !== undefined) { | ||
throw "Could not change window.document"; | ||
} | ||
} catch (e) { | ||
return; // Can't change window.document in current env, so skip these tests | ||
} | ||
window.document = originalDocument; | ||
log.setLevel("debug"); | ||
beforeEach(function() { | ||
window.document = undefined; | ||
expect('debug').toBeTheStoredLevel(); | ||
}); | ||
it("warn is the default log level", function(log) { | ||
expect(log).toBeAtLevel("warn"); | ||
}); | ||
it("log can be changed to info level", function(log) { | ||
log.setLevel("info"); | ||
expect(log).toBeAtLevel("info"); | ||
}); | ||
it("log.setLevel() does nothing with cookies or the document when the level is changed", function(log) { | ||
log.setLevel("silent"); | ||
expect(window.document).not.toBeDefined(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -14,3 +14,3 @@ "use strict"; | ||
describe("Log levels", function() { | ||
describe("Basic log levels changing tests:", function() { | ||
beforeEach(function() { | ||
@@ -54,4 +54,4 @@ window.console = {}; | ||
describe("invalid setLevel inputs", function() { | ||
it("error thrown if no level is given", function() { | ||
describe("log.setLevel() throws errors if given", function() { | ||
it("no level argument", function() { | ||
expect(function() { | ||
@@ -62,3 +62,3 @@ log.setLevel(); | ||
it("error thrown if null level is given", function() { | ||
it("a null level argument", function() { | ||
expect(function() { | ||
@@ -69,3 +69,3 @@ log.setLevel(null); | ||
it("error thrown if undefined level is given", function() { | ||
it("an undefined level argument", function() { | ||
expect(function() { | ||
@@ -76,3 +76,3 @@ log.setLevel(undefined); | ||
it("error thrown if invalid level number is given", function() { | ||
it("an invalid log level index", function() { | ||
expect(function() { | ||
@@ -83,3 +83,3 @@ log.setLevel(-1); | ||
it("error thrown if invalid level name is given", function() { | ||
it("an invalid log level name", function() { | ||
expect(function() { | ||
@@ -86,0 +86,0 @@ log.setLevel("InvalidLevelName"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
116
3
1
66343
19
1279