Skip to content

Instantly share code, notes, and snippets.

@cjmyles
Created March 4, 2014 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjmyles/9357477 to your computer and use it in GitHub Desktop.
Save cjmyles/9357477 to your computer and use it in GitHub Desktop.
Utils - Cross browser logging
utils = {
log: function() {
this.__log("log", arguments);
},
info: function() {
this.__log("info", arguments);
},
warn: function() {
this.__log("warn", arguments);
},
error: function() {
this.__log("error", arguments);
},
__log: function() {
var type = arguments[0];
if (this._debug && typeof console !== "undefined" && console !== null && typeof console[type] !== "undefined" && console[type] !== null) {
var _ref = console[type],
_ref1;
if (typeof _ref !== "undefined" && _ref !== null && typeof _ref.apply !== "undefined" && _ref.apply !== null) {
_ref.apply(console, (_ref1 = [type + ":"]).concat.apply(_ref1, arguments[1]));
} else {
var str = "";
_.each(arguments[1], function(a){
if (typeof a === "string") {
str += str.length > 0 ? ", " + a : a;
} else {
if (str.length > 0) {
_ref(str);
str = "";
}
_ref(JSON.stringify(a));
}
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment