Commit 4e490488 4e49048821fff46037fe41b2a6935ccfd00b5ff7 by Nicolas Perriault

refactored Casper.log(), added Casper.logFormats to setup custom log message formatters

1 parent a2282c1c
Showing 1 changed file with 13 additions and 6 deletions
......@@ -71,6 +71,7 @@
this.delayedExecution = false;
this.history = [];
this.loadInProgress = false;
this.logFormats = {};
this.logLevels = ["debug", "info", "warning", "error"];
this.logStyles = {
debug: 'INFO',
......@@ -576,16 +577,22 @@
if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) {
return this; // skip logging
}
if (this.options.verbose) {
var levelStr = this.colorizer.colorize('[' + level + ']', this.logStyles[level]);
this.echo(levelStr + ' [' + space + '] ' + message); // direct output
}
this.result.log.push({
var entry = {
level: level,
space: space,
message: message,
date: new Date().toString()
});
};
if (level in this.logFormats && isType(this.logFormats[level], "function")) {
message = this.logFormats[level](message, level, space);
} else {
var levelStr = this.colorizer.colorize('[' + level + ']', this.logStyles[level]);
message = levelStr + ' [' + space + '] ' + message;
}
if (this.options.verbose) {
this.echo(message); // direct output
}
this.result.log.push(entry);
return this;
},
......