Skip to content

Commit

Permalink
feat(client): capture all console.* log methods
Browse files Browse the repository at this point in the history
  • Loading branch information
timbertson committed Jun 8, 2013
1 parent 9dde7f1 commit 683e6dc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions static/karma.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Karma = function(socket, context, navigator, location) {
var getConsole = function(currentWindow) {
return currentWindow.console || {
log: function() {},
info: function() {},
warn: function() {},
error: function() {},
debug: function() {}
Expand All @@ -69,11 +70,20 @@ var Karma = function(socket, context, navigator, location) {
// patch the console
var localConsole = contextWindow.console = getConsole(contextWindow);
var browserConsoleLog = localConsole.log;

localConsole.log = function() {
contextWindow.__karma__.info({dump: Array.prototype.slice.call(arguments, 0)});
return Function.prototype.apply.call(browserConsoleLog, localConsole, arguments);
var logMethods = ['log', 'info', 'warn', 'error', 'debug'];
var patchConsoleMethod = function(method) {
var orig = localConsole[method];
if (!orig) {
return;
}
localConsole[method] = function() {
contextWindow.__karma__.info({dump: Array.prototype.slice.call(arguments, 0)});
return Function.prototype.apply.call(orig, localConsole, arguments);
};
};
for (var i = 0; i < logMethods.length; i++) {
patchConsoleMethod(logMethods[i]);
}
};

var clearContext = function() {
Expand Down

0 comments on commit 683e6dc

Please sign in to comment.