Socket
Socket
Sign inDemoInstall

loglevel

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loglevel - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

2

bower.json
{
"name": "loglevel",
"version": "0.4.0",
"version": "0.5.0",
"main": "dist/loglevel.min.js",

@@ -5,0 +5,0 @@ "dependencies": {},

@@ -1,5 +0,5 @@

/*! loglevel - v0.4.0 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
/*! loglevel - v0.5.0 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
;(function (undefined) {
var undefinedType = "undefined";
(function (name, definition) {

@@ -35,7 +35,10 @@ if (typeof module !== 'undefined') {

if (Function.prototype.bind === undefined) {
return function() {
Function.prototype.apply.apply(method, [console, arguments]);
};
return functionBindingWrapper(method, console);
} else {
return Function.prototype.bind.call(console[methodName], console);
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);
}
}

@@ -47,2 +50,8 @@ } else {

function functionBindingWrapper(f, context) {
return function() {
Function.prototype.apply.apply(f, [context, arguments]);
};
}
var logMethods = [

@@ -56,5 +65,5 @@ "trace",

function clearMethods() {
function replaceLoggingMethods(methodFactory) {
for (var ii = 0; ii < logMethods.length; ii++) {
self[logMethods[ii]] = noop;
self[logMethods[ii]] = methodFactory(logMethods[ii]);
}

@@ -128,17 +137,24 @@ }

if (level === self.levels.SILENT) {
clearMethods();
replaceLoggingMethods(function () {
return noop;
});
return;
} else if (typeof console === undefinedType) {
clearMethods();
throw "No console available for logging";
replaceLoggingMethods(function (methodName) {
return function () {
if (typeof console !== undefinedType) {
self.setLevel(level);
self[methodName].apply(self, arguments);
}
};
});
return "No console available for logging";
} else {
for (var ii = 0; ii < logMethods.length; ii++) {
var methodName = logMethods[ii];
replaceLoggingMethods(function (methodName) {
if (level <= self.levels[methodName.toUpperCase()]) {
self[methodName] = realMethod(methodName);
return realMethod(methodName);
} else {
self[methodName] = noop;
return noop;
}
}
});
}

@@ -160,9 +176,5 @@ } else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {

try {
loadPersistedLevel();
} catch (e) {
self.setLevel(self.levels.SILENT);
}
loadPersistedLevel();
return self;
}));
})();

@@ -1,2 +0,2 @@

/*! loglevel - v0.4.0 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
!function(a){var b="undefined";!function(a,b){"undefined"!=typeof module?module.exports=b():"function"==typeof define&&"object"==typeof define.amd?define(b):this[a]=b()}("log",function(){function c(c){return typeof console===b?k:console[c]===a?console.log!==a?d(console,"log"):k:d(console,c)}function d(b,c){var d=b[c];return d.bind===a?Function.prototype.bind===a?function(){Function.prototype.apply.apply(d,[b,arguments])}:Function.prototype.bind.call(b[c],b):b[c].bind(b)}function e(){for(var a=0;a<l.length;a++)j[l[a]]=k}function f(){return typeof window!==b&&window.document!==a&&window.document.cookie!==a}function g(){try{return typeof window!==b&&window.localStorage!==a}catch(c){return!1}}function h(a){var b;for(var c in j.levels)if(j.levels.hasOwnProperty(c)&&j.levels[c]===a){b=c;break}if(g())window.localStorage.loglevel=b;else{if(!f())return;window.document.cookie="loglevel="+b+";"}}function i(){var a;if(g()&&(a=window.localStorage.loglevel),!a&&f()){var b=m.exec(window.document.cookie)||[];a=b[1]}j.setLevel(j.levels[a]||j.levels.WARN)}var j={},k=function(){},l=["trace","debug","info","warn","error"],m=/loglevel=([^;]+)/;j.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},j.setLevel=function(d){if("number"==typeof d&&d>=0&&d<=j.levels.SILENT){if(h(d),d===j.levels.SILENT)return e(),void 0;if(typeof console===b)throw e(),"No console available for logging";for(var f=0;f<l.length;f++){var g=l[f];j[g]=d<=j.levels[g.toUpperCase()]?c(g):k}}else{if("string"!=typeof d||j.levels[d.toUpperCase()]===a)throw"log.setLevel() called with invalid level: "+d;j.setLevel(j.levels[d.toUpperCase()])}},j.enableAll=function(){j.setLevel(j.levels.TRACE)},j.disableAll=function(){j.setLevel(j.levels.SILENT)};try{i()}catch(n){j.setLevel(j.levels.SILENT)}return j})}();
/*! loglevel - v0.5.0 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
!function(a){var b="undefined";!function(a,b){"undefined"!=typeof module?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}catch(c){return!1}}function i(a){var b;for(var c in k.levels)if(k.levels.hasOwnProperty(c)&&k.levels[c]===a){b=c;break}if(h())window.localStorage.loglevel=b;else{if(!g())return;window.document.cookie="loglevel="+b+";"}}function j(){var a;if(h()&&(a=window.localStorage.loglevel),!a&&g()){var b=n.exec(window.document.cookie)||[];a=b[1]}k.setLevel(k.levels[a]||k.levels.WARN)}var k={},l=function(){},m=["trace","debug","info","warn","error"],n=/loglevel=([^;]+)/;return 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 f(function(){return l}),void 0;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)},j(),k})}();

@@ -69,28 +69,32 @@ 'use strict';

'saucelabs-jasmine': {
// Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
all: {
username: 'pimterry',
key: 'KEY',
urls: ['http://localhost:8000/_SpecRunner.html'],
browsers: [
{"browserName": "iehta", "platform": "Windows 2008", "version": "9"},
// {"browserName": "firefox", "platform": "Windows 2003", "version": "3.0"},
// {"browserName": "firefox", "platform": "Windows 2003", "version": "3.5"},
{"browserName": "firefox", "platform": "Windows 2003", "version": "3.6"},
{"browserName": "firefox", "platform": "Windows 2003", "version": "4"},
{"browserName": "firefox", "platform": "Windows 2003", "version": "19"},
{"browserName": "safari", "platform": "Mac 10.6", "version": "5"},
{"browserName": "safari", "platform": "Mac 10.8", "version": "6"},
{"browserName": "googlechrome", "platform": "Windows 2003"},
{"browserName": "opera", "platform": "Windows 2003", "version": "12"},
{"browserName": "iehta", "platform": "Windows 2003", "version": "6"},
{"browserName": "iehta", "platform": "Windows 2003", "version": "7"},
{"browserName": "iehta", "platform": "Windows 2008", "version": "8"}
],
concurrency: 3,
detailedError: true,
testTimeout:10000,
testInterval:1000,
testReadyTimeout:2000,
testname: 'loglevel jasmine test',
tags: [process.env.TRAVIS_REPO_SLUG || "local", process.env.TRAVIS_COMMIT || "manual"]
options: {
urls: ['http://localhost:8000/_SpecRunner.html'],
browsers: [
{"browserName": "firefox", "platform": "Windows 2003", "version": "3.6"},
{"browserName": "firefox", "platform": "Windows 2003", "version": "4"},
{"browserName": "firefox", "platform": "Windows 2003", "version": "25"},
{"browserName": "safari", "platform": "Mac 10.6", "version": "5"},
{"browserName": "safari", "platform": "Mac 10.8", "version": "6"},
{"browserName": "googlechrome", "platform": "Windows 7"},
{"browserName": "opera", "platform": "Windows 2003", "version": "12"},
// Disabled because old IE breaks the Jasmine runner; these have to be manually tested
// {"browserName": "iehta", "platform": "Windows XP", "version": "6"},
// {"browserName": "iehta", "platform": "Windows XP", "version": "7"},
// {"browserName": "iehta", "platform": "Windows XP", "version": "8"},
{"browserName": "iehta", "platform": "Windows 7", "version": "9"},
{"browserName": "iehta", "platform": "Windows 7", "version": "10"},
{"browserName": "opera", "platform": "Windows 7", "version": "12"},
{"browserName": "android", "platform": "Linux", "version": "4.0"},
{"browserName": "iphone", "platform": "OS X 10.8", "version": "6"}
],
concurrency: 3,
detailedError: true,
testTimeout:10000,
testInterval:1000,
testReadyTimeout:2000,
testname: 'loglevel jasmine test',
tags: [process.env.TRAVIS_REPO_SLUG || "local", process.env.TRAVIS_COMMIT || "manual"]
}
}

@@ -147,3 +151,3 @@ },

// Build a distributable release
grunt.registerTask('dist', ['test', 'uglify']);
grunt.registerTask('dist', ['test', 'concat', 'uglify']);

@@ -154,10 +158,10 @@ // Just tests

// Test with a live server and an actual browser
grunt.registerTask('integration-test', ['jasmine:src:build', 'connect:test:keepalive', 'open:jasmine']);
grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);
// Test with lots of browsers on saucelabs
grunt.registerTask('saucelabs', ['jasmine:src:build', 'connect:test', 'saucelabs-jasmine']);
// Test with lots of browsers on saucelabs. Requires valid SAUCE_USERNAME and SAUCE_ACCESS_KEY in env to run.
grunt.registerTask('saucelabs', ['jasmine:requirejs:src:build', 'connect:test', 'saucelabs-jasmine']);
// Default task.
grunt.registerTask('default', 'dist');
grunt.registerTask('default', 'test');
};

@@ -10,3 +10,3 @@ /*

var undefinedType = "undefined";
(function (name, definition) {

@@ -42,7 +42,10 @@ if (typeof module !== 'undefined') {

if (Function.prototype.bind === undefined) {
return function() {
Function.prototype.apply.apply(method, [console, arguments]);
};
return functionBindingWrapper(method, console);
} else {
return Function.prototype.bind.call(console[methodName], console);
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);
}
}

@@ -54,2 +57,8 @@ } else {

function functionBindingWrapper(f, context) {
return function() {
Function.prototype.apply.apply(f, [context, arguments]);
};
}
var logMethods = [

@@ -63,5 +72,5 @@ "trace",

function clearMethods() {
function replaceLoggingMethods(methodFactory) {
for (var ii = 0; ii < logMethods.length; ii++) {
self[logMethods[ii]] = noop;
self[logMethods[ii]] = methodFactory(logMethods[ii]);
}

@@ -135,17 +144,24 @@ }

if (level === self.levels.SILENT) {
clearMethods();
replaceLoggingMethods(function () {
return noop;
});
return;
} else if (typeof console === undefinedType) {
clearMethods();
throw "No console available for logging";
replaceLoggingMethods(function (methodName) {
return function () {
if (typeof console !== undefinedType) {
self.setLevel(level);
self[methodName].apply(self, arguments);
}
};
});
return "No console available for logging";
} else {
for (var ii = 0; ii < logMethods.length; ii++) {
var methodName = logMethods[ii];
replaceLoggingMethods(function (methodName) {
if (level <= self.levels[methodName.toUpperCase()]) {
self[methodName] = realMethod(methodName);
return realMethod(methodName);
} else {
self[methodName] = noop;
return noop;
}
}
});
}

@@ -167,9 +183,5 @@ } else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {

try {
loadPersistedLevel();
} catch (e) {
self.setLevel(self.levels.SILENT);
}
loadPersistedLevel();
return self;
}));
})();
{
"name": "loglevel",
"description": "Minimal lightweight logging for JavaScript, adding reliable log level methods to any available console.log methods",
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/pimterry/loglevel",

@@ -42,3 +42,3 @@ "author": {

"grunt-open": "~0.2.2",
"grunt-saucelabs": "~4.0.4",
"grunt-saucelabs": "~4.1.2",
"grunt-contrib-connect": "~0.5.0",

@@ -45,0 +45,0 @@ "grunt-jasmine-node": "~0.1.0"

@@ -13,2 +13,3 @@ # loglevel [![Build Status](https://travis-ci.org/pimterry/loglevel.png)](https://travis-ci.org/pimterry/loglevel) [![Dependency status](https://david-dm.org/pimterry/loglevel/dev-status.png)](https://david-dm.org/pimterry/loglevel#info=devDependencies&view=table)

* Filter logging by level (all the above or 'silent'), so you can disable all but error logging in production, and then run log.setLevel("trace") in your console to turn it all back on for a furious debugging session
* Single file, no dependencies, weighs in at <1KB minified and gzipped

@@ -19,4 +20,4 @@ ### Effective

* Logging calls still succeed even if there's no console object at all, so your site doesn't break when people visit with old browsers that don't support the console object (here's looking at you IE) and similar
* This then comes together giving a consistent reliable API that works in every JavaScript environment with a console available, and doesn't break anything anywhere else
* This then comes together giving a consistent reliable API that works in every JavaScript environment with a console available, and never breaks anything anywhere else
### Convenient

@@ -27,2 +28,3 @@

* Logging is filtered to "warn" level by default, to keep your live site clean in normal usage (or you can trivially re-enable everything with an initial log.enableAll() call)
* Magically handles situations where console logging is not initially available (IE8/9), and automatically enables logging as soon as it does become available (when developer console is opened)

@@ -35,3 +37,3 @@ ## Downloading 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.
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.4.0/loglevel.min.js`

@@ -91,10 +93,10 @@ 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.

This can take either a log level name or 'silent' (which disables everything) in one of a few forms:
* As a log level from the internal levels list, e.g. log.levels.SILENT <- for type safety
* As a string, like 'error' (case-insensitive) <- for a reasonable practical balance
* As a numeric index from 0 (trace) to 5 (silent) <- deliciously terse, and more easily programmable (...although, why?)
* As a log level from the internal levels list, e.g. log.levels.SILENT ← _for type safety_
* As a string, like 'error' (case-insensitive) ← _for a reasonable practical balance_
* As a numeric index from 0 (trace) to 5 (silent) ← _deliciously terse, and more easily programmable (...although, why?)_
Where possible the log level will be persisted. LocalStorage will be used if available, falling back to cookies if not. If neither is available in the current environment (i.e. in Node) persistence will be skipped.
It is expected that log.setLevel() will be manually called during debugging and similar, and as such you should note that **log.setLevel() will throw an error if you attempt to set the level to a non-silent level and there is no console available.** If you do want to explicitly change the default log level from warn in your codebase you should do so in a try/catch. Failing setLevel calls due to a missing console are equivalent to log.setLevel("silent"), which never fails.
If log.setLevel() is called when a console object is not available (in IE 8 or 9 before the developer tools have been opened, for example) logging will remain silent until the console becomes available, and then begin logging at the requested level.
* `log.enableAll()` and `log.disableAll()` methods.

@@ -122,2 +124,3 @@

* Run `jam publish` to publish to JamJS
* Open a pull request to https://github.com/cdnjs/cdnjs to put the new release on the CDN

@@ -135,2 +138,4 @@ ## Release History

v0.5.0 - Fix for Modernizr+IE8 issues, improved setLevel error handling, support for auto-activation of desired logging when console eventually turns up in IE8
## License

@@ -137,0 +142,0 @@ Copyright (c) 2013 Tim Perry

@@ -11,2 +11,6 @@ "use strict";

function mockConsole() {
return {"log" : jasmine.createSpy("console.log")};
}
define(['../lib/loglevel'], function(log) {

@@ -26,22 +30,44 @@ var originalConsole = window.console;

it("silent method calls are allowed", function() {
log.setLevel(log.levels.SILENT);
var result = log.setLevel(log.levels.SILENT);
log.trace("hello");
});
it("setting an active level fails", function() {
expect(function() {
log.setLevel(log.levels.TRACE);
}).toThrow("No console available for logging");
expect(result).toBeUndefined();
});
it("setting to silent level is fine", function() {
log.setLevel(log.levels.SILENT);
it("setting an active level gently returns an error string", function() {
var result = log.setLevel(log.levels.TRACE);
expect(result).toEqual("No console available for logging");
});
it("active method calls are allowed, once the active setLevel fails", function() {
try {
log.setLevel(log.levels.TRACE);
} catch (e) { }
log.setLevel(log.levels.TRACE);
log.trace("hello");
});
describe("if a console later appears", function () {
it("logging is re-enabled and works correctly when next used", function () {
log.setLevel(log.levels.WARN);
window.console = mockConsole();
log.error("error");
expect(window.console.log).toHaveBeenCalled();
});
it("logging is re-enabled but does nothing when used at a blocked level", function () {
log.setLevel(log.levels.WARN);
window.console = mockConsole();
log.trace("trace");
expect(window.console.log).not.toHaveBeenCalled();
});
it("changing level works correctly from that point", function () {
window.console = mockConsole();
var result = log.setLevel(log.levels.WARN);
expect(result).toBeUndefined();
});
});
});

@@ -51,3 +77,3 @@

beforeEach(function() {
window.console = {"log" : jasmine.createSpy("console.log")};
window.console = mockConsole();
});

@@ -54,0 +80,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc