Skip to content

Instantly share code, notes, and snippets.

@jonsamwell
Created July 6, 2013 07:45
Show Gist options
  • Save jonsamwell/5939156 to your computer and use it in GitHub Desktop.
Save jonsamwell/5939156 to your computer and use it in GitHub Desktop.
Added console support to older browsers (IE8 / 9)
(function (window, Function, $, YourNamespace) {
"use strict";
if (Function.prototype.bind && typeof console == "object" && typeof console.log == "object") {
var logFns = ["log", "info", "warn", "error", "assert", "dir", "clear", "profile", "profileEnd"];
$.each(logFns, function (i, method) {
console[method] = Function.prototype.call.bind(console[method], console);
});
}
YourNamespace.Logger = (function () {
var write = function (method, args) {
if (typeof window.console !== "undefined" && window.console[method] !== "undefined") {
console[method].call(window.console, args);
}
},
log = function (msg) {
write('log', msg);
},
error = function (msg, error) {
write('error', msg, error);
};
return {
log: log,
error: error
};
}());
}(window, Function, $, YourNamespace));
/*
Usage: YourNamespace.Logger.log('hello world');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment