Created
March 4, 2014 22:55
-
-
Save cjmyles/9357477 to your computer and use it in GitHub Desktop.
Utils - Cross browser logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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