Skip to content

Instantly share code, notes, and snippets.

@dominykas
Created March 7, 2014 14:31
Show Gist options
  • Save dominykas/9412480 to your computer and use it in GitHub Desktop.
Save dominykas/9412480 to your computer and use it in GitHub Desktop.
["log", "info", "warn", "error"].forEach(function (k) {
var originalFn = console[k];
console[k] = function (s, o) {
if (arguments.length == 1 && typeof(s) == "string") {
originalFn.call(this, s + " " + JSON.stringify({message: s}));
return;
}
if (arguments.length == 2 && typeof(s) == "string" && typeof (o) == "object") {
var logObject = _.merge({}, o, { message: s });
originalFn.call(this, s + " " + JSON.stringify(logObject));
return;
}
if (arguments.length > 2 && k === "error") {
console.warn("console.error with arguments.length > 2");
}
originalFn.apply(this, arguments);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment