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.3.1 to 0.4.0

component.js

2

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

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

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

/*! loglevel - v0.3.1 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
/*! loglevel - v0.4.0 - https://github.com/pimterry/loglevel - (c) 2013 Tim Perry - licensed MIT */
;(function (undefined) {

@@ -21,3 +21,7 @@ var undefinedType = "undefined";

} else if (console[methodName] === undefined) {
return boundToConsole(console, 'log') || noop;
if (console.log !== undefined) {
return boundToConsole(console, 'log');
} else {
return noop;
}
} else {

@@ -33,3 +37,3 @@ return boundToConsole(console, methodName);

return function() {
method.apply(console, arguments);
Function.prototype.apply.apply(method, [console, arguments]);
};

@@ -64,7 +68,12 @@ } else {

function setLevelInCookie(levelNum) {
if (!cookiesAvailable()) {
return;
function localStorageAvailable() {
try {
return (typeof window !== undefinedType &&
window.localStorage !== undefined);
} catch (e) {
return false;
}
}
function persistLevelIfPossible(levelNum) {
var levelName;

@@ -79,4 +88,8 @@

if (levelName !== undefined) {
if (localStorageAvailable()) {
window.localStorage['loglevel'] = levelName;
} else if (cookiesAvailable()) {
window.document.cookie = "loglevel=" + levelName + ";";
} else {
return;
}

@@ -87,11 +100,15 @@ }

function loadLevelFromCookie() {
var cookieLevel;
function loadPersistedLevel() {
var storedLevel;
if (cookiesAvailable()) {
if (localStorageAvailable()) {
storedLevel = window.localStorage['loglevel'];
}
if (!storedLevel && cookiesAvailable()) {
var cookieMatch = cookieRegex.exec(window.document.cookie) || [];
cookieLevel = cookieMatch[1];
storedLevel = cookieMatch[1];
}
self.setLevel(self.levels[cookieLevel] || self.levels.WARN);
self.setLevel(self.levels[storedLevel] || self.levels.WARN);
}

@@ -110,3 +127,3 @@

if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
setLevelInCookie(level);
persistLevelIfPossible(level);

@@ -130,3 +147,3 @@ if (level === self.levels.SILENT) {

}
} else if (typeof level === "string") {
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
self.setLevel(self.levels[level.toUpperCase()]);

@@ -147,3 +164,3 @@ } else {

try {
loadLevelFromCookie();
loadPersistedLevel();
} catch (e) {

@@ -150,0 +167,0 @@ self.setLevel(self.levels.SILENT);

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

/*! 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})})();
/*! 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})}();

@@ -22,3 +22,3 @@ 'use strict';

dest: 'dist/<%= pkg.name %>.js'
},
}
},

@@ -35,10 +35,25 @@ uglify: {

jasmine: {
src: 'src/**/*.js',
options: {
specs: 'test/*-test.js',
vendor: 'test/vendor/*.js',
helpers: 'test/*-helper.js',
template: require('grunt-template-jasmine-requirejs')
requirejs: {
src: [],
options: {
specs: 'test/*-test.js',
vendor: 'test/vendor/*.js',
helpers: 'test/*-helper.js',
template: require('grunt-template-jasmine-requirejs')
}
},
global: {
src: 'lib/**/*.js',
options: {
specs: 'test/global-integration.js',
vendor: 'test/vendor/*.js'
}
}
},
"jasmine_node": {
match: "node-integration.",
matchall: true,
projectRoot: "./test",
useHelpers: false
},
open: {

@@ -73,3 +88,3 @@ jasmine: {

{"browserName": "iehta", "platform": "Windows 2003", "version": "7"},
{"browserName": "iehta", "platform": "Windows 2008", "version": "8"},
{"browserName": "iehta", "platform": "Windows 2008", "version": "8"}
],

@@ -103,3 +118,3 @@ concurrency: 3,

src: ['test/*.js']
},
}
},

@@ -118,4 +133,4 @@ watch: {

tasks: ['jshint:test', 'jasmine']
},
},
}
}
});

@@ -127,2 +142,3 @@

grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-contrib-jshint');

@@ -135,7 +151,7 @@ grunt.loadNpmTasks('grunt-contrib-watch');

// Default task.
grunt.registerTask('default', ['jshint', 'jasmine', 'concat', 'uglify']);
// Build a distributable release
grunt.registerTask('dist', ['test', 'uglify']);
// Just tests
grunt.registerTask('test', ['jshint', 'jasmine']);
grunt.registerTask('test', ['jshint', 'jasmine:requirejs', 'jasmine:global', 'jasmine_node']);

@@ -148,2 +164,5 @@ // Test with a live server and an actual browser

// Default task.
grunt.registerTask('default', 'dist');
};

@@ -27,3 +27,7 @@ /*

} else if (console[methodName] === undefined) {
return boundToConsole(console, 'log') || noop;
if (console.log !== undefined) {
return boundToConsole(console, 'log');
} else {
return noop;
}
} else {

@@ -39,3 +43,3 @@ return boundToConsole(console, methodName);

return function() {
method.apply(console, arguments);
Function.prototype.apply.apply(method, [console, arguments]);
};

@@ -70,7 +74,12 @@ } else {

function setLevelInCookie(levelNum) {
if (!cookiesAvailable()) {
return;
function localStorageAvailable() {
try {
return (typeof window !== undefinedType &&
window.localStorage !== undefined);
} catch (e) {
return false;
}
}
function persistLevelIfPossible(levelNum) {
var levelName;

@@ -85,4 +94,8 @@

if (levelName !== undefined) {
if (localStorageAvailable()) {
window.localStorage['loglevel'] = levelName;
} else if (cookiesAvailable()) {
window.document.cookie = "loglevel=" + levelName + ";";
} else {
return;
}

@@ -93,11 +106,15 @@ }

function loadLevelFromCookie() {
var cookieLevel;
function loadPersistedLevel() {
var storedLevel;
if (cookiesAvailable()) {
if (localStorageAvailable()) {
storedLevel = window.localStorage['loglevel'];
}
if (!storedLevel && cookiesAvailable()) {
var cookieMatch = cookieRegex.exec(window.document.cookie) || [];
cookieLevel = cookieMatch[1];
storedLevel = cookieMatch[1];
}
self.setLevel(self.levels[cookieLevel] || self.levels.WARN);
self.setLevel(self.levels[storedLevel] || self.levels.WARN);
}

@@ -116,3 +133,3 @@

if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
setLevelInCookie(level);
persistLevelIfPossible(level);

@@ -136,3 +153,3 @@ if (level === self.levels.SILENT) {

}
} else if (typeof level === "string") {
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
self.setLevel(self.levels[level.toUpperCase()]);

@@ -153,3 +170,3 @@ } else {

try {
loadLevelFromCookie();
loadPersistedLevel();
} catch (e) {

@@ -156,0 +173,0 @@ self.setLevel(self.levels.SILENT);

{
"name": "loglevel",
"description": "Minimal lightweight logging for JavaScript, adding reliable log level methods to any available console.log methods",
"version": "0.3.1",
"version": "0.4.0",
"homepage": "https://github.com/pimterry/loglevel",

@@ -31,16 +31,16 @@ "author": {

},
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.6",
"grunt-contrib-concat": "~0.1.2",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-watch": "~0.2.0",
"grunt-contrib-jasmine": "~0.4.1",
"grunt-template-jasmine-requirejs": "~0.1.0",
"grunt-open": "~0.2.0",
"grunt-contrib-connect": "~0.2.0",
"grunt-saucelabs": "~3.0.7"
"grunt-cli": "~0.1.9",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-jasmine": "~0.5.2",
"grunt-template-jasmine-requirejs": "~0.1.6",
"grunt-open": "~0.2.2",
"grunt-saucelabs": "~4.0.4",
"grunt-contrib-connect": "~0.5.0",
"grunt-jasmine-node": "~0.1.0"
},

@@ -51,3 +51,8 @@ "jam": {

},
"keywords": ["log", "logger", "logging", "browser"]
"keywords": [
"log",
"logger",
"logging",
"browser"
]
}

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

# loglevel [![Build Status](https://travis-ci.org/pimterry/loglevel.png)](https://travis-ci.org/pimterry/loglevel)
# 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)

@@ -34,2 +34,4 @@ Minimal lightweight simple logging for JavaScript. loglevel replaces console.log() and friends with level-based logging and filtering, with none of console's downsides.

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.
[min]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.min.js

@@ -90,3 +92,3 @@ [max]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.js

Where possible the loglevel will be persisted as a session cookie on the current domain. If cookies are not available in the current environment (i.e. in Node) this step will be skipped.
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.

@@ -99,7 +101,21 @@ 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.

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Builds can be run with grunt, just run 'grunt' in the root directory of the project.
## Developing & Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
_Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
Builds can be run with grunt: run `grunt dist` to build a distributable version of the project (in /dist), or `grunt test` to just run the tests and linting. During development you can run `grunt watch` and it will monitor source files, and rerun the tests and linting as appropriate when they're changed.
_Also, please don't manually edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
#### Release process
To do a release of loglevel:
* Update the version number in package.json and bower.json
* Run `grunt dist` to build a distributable version in dist/
* Update the release history in this file (below)
* Commit the built code, tagging it with the version number and a brief message about the release
* Push to Github
* Run `npm publish .` to publish to NPM
* Run `jam publish` to publish to JamJS
## Release History

@@ -114,2 +130,4 @@ v0.1.0 - First working release with apparent compatibility with everything tested

v0.4.0 - Use LocalStorage for level persistence if available, compatibility improvements for IE, improved error messages, multi-environment tests
## License

@@ -116,0 +134,0 @@ Copyright (c) 2013 Tim Perry

@@ -10,3 +10,4 @@ "use strict";

describeIf(testHelpers.isCookieStorageAvailable(), "Cookie persistence tests:", function() {
describeIf(testHelpers.isCookieStorageAvailable() && !testHelpers.isLocalStorageAvailable(),
"Cookie-only persistence tests:", function() {

@@ -13,0 +14,0 @@ beforeEach(function() {

@@ -57,3 +57,3 @@ "use strict";

log.setLevel();
}).toThrow();
}).toThrow("log.setLevel() called with invalid level: undefined");
});

@@ -64,3 +64,3 @@

log.setLevel(null);
}).toThrow();
}).toThrow("log.setLevel() called with invalid level: null");
});

@@ -71,3 +71,3 @@

log.setLevel(undefined);
}).toThrow();
}).toThrow("log.setLevel() called with invalid level: undefined");
});

@@ -78,3 +78,3 @@

log.setLevel(-1);
}).toThrow();
}).toThrow("log.setLevel() called with invalid level: -1");
});

@@ -85,3 +85,3 @@

log.setLevel("InvalidLevelName");
}).toThrow();
}).toThrow("log.setLevel() called with invalid level: InvalidLevelName");
});

@@ -88,0 +88,0 @@ });

@@ -41,3 +41,2 @@ "use strict";

window.document.cookie = "test=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
window.document.cookie = ""; // No-op for real cookie impl, but clears cookies if they're just mocked

@@ -126,24 +125,29 @@ return result;

// Wraps the Jasmine it(name, test) call with some require magic to reload the loglevel
// dependency for the given test
self.itWithFreshLog = function itWithFreshLog(name, test) {
jasmine.getEnv().it(name, function() {
require.undef("lib/loglevel");
// Forcibly reloads loglevel, and asynchronously hands the resulting log back to the given callback
// via Jasmine async magic
self.withFreshLog = function withFreshLog(toRun) {
require.undef("lib/loglevel");
var freshLog;
var freshLog;
waitsFor(function() {
require(['lib/loglevel'], function(log) {
freshLog = log;
});
return typeof freshLog !== "undefined";
waitsFor(function() {
require(['lib/loglevel'], function(log) {
freshLog = log;
});
return typeof freshLog !== "undefined";
});
runs(function() {
test(freshLog);
});
runs(function() {
toRun(freshLog);
});
};
// Wraps Jasmine's it(name, test) call to reload the loglevel dependency for the given test
self.itWithFreshLog = function itWithFreshLog(name, test) {
jasmine.getEnv().it(name, function() {
self.withFreshLog(test);
});
};
return self;
});

@@ -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

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