Skip to content

Commit

Permalink
0.5.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Oct 13, 2013
1 parent 8d9a705 commit 3998110
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ This is a barebones reliable everyday logging library. It does not do fancy thin

* Log things at a given level (trace/debug/info/warn/error) to the console object (as seen in all modern browsers & node.js)
* 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

### Effective

* Log methods gracefully fall back to simpler console logging methods if more specific ones aren't available: so calls to log.debug() go to console.debug() if possible, or console.log() if not
* 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

* Log output keeps line numbers: most JS logging frameworks call console.log methods through wrapper functions, clobbering your stacktrace and making the extra info many browsers provide useless. We'll have none of that thanks.
* It works with all the standard JavaScript loading systems out of the box (CommonJS, AMD, or just as a global)
* 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)

## Downloading loglevel

Expand Down Expand Up @@ -90,7 +92,7 @@ The loglevel API is extremely minimal. All methods are available on the root log

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.

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 begins logging at the requested level.
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.

Expand Down Expand Up @@ -127,6 +129,8 @@ v0.3.1 - Fixed incorrect text in release build banner, various other minor tweak

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

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
Copyright (c) 2013 Tim Perry
Licensed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loglevel",
"version": "0.4.0",
"version": "0.5.0",
"main": "dist/loglevel.min.js",
"dependencies": {},
"ignore": [
Expand Down
56 changes: 34 additions & 22 deletions dist/loglevel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! 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) {
if (typeof module !== 'undefined') {
module.exports = definition();
Expand Down Expand Up @@ -32,17 +32,26 @@
var method = console[methodName];
if (method.bind === 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);
}
}
} else {
return console[methodName].bind(console);
}
}

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

var logMethods = [
"trace",
"debug",
Expand All @@ -51,9 +60,9 @@
"error"
];

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

Expand Down Expand Up @@ -122,21 +131,28 @@
persistLevelIfPossible(level);

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;
}
}
});
}
} else if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
self.setLevel(self.levels[level.toUpperCase()]);
Expand All @@ -153,11 +169,7 @@
self.setLevel(self.levels.SILENT);
};

try {
loadPersistedLevel();
} catch (e) {
self.setLevel(self.levels.SILENT);
}
loadPersistedLevel();
return self;
}));
})();
4 changes: 2 additions & 2 deletions dist/loglevel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"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",
"author": {
"name": "Tim Perry",
Expand Down

0 comments on commit 3998110

Please sign in to comment.