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 @@ ...@@ -71,6 +71,7 @@
71 this.delayedExecution = false; 71 this.delayedExecution = false;
72 this.history = []; 72 this.history = [];
73 this.loadInProgress = false; 73 this.loadInProgress = false;
74 this.logFormats = {};
74 this.logLevels = ["debug", "info", "warning", "error"]; 75 this.logLevels = ["debug", "info", "warning", "error"];
75 this.logStyles = { 76 this.logStyles = {
76 debug: 'INFO', 77 debug: 'INFO',
...@@ -576,16 +577,22 @@ ...@@ -576,16 +577,22 @@
576 if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) { 577 if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) {
577 return this; // skip logging 578 return this; // skip logging
578 } 579 }
579 if (this.options.verbose) { 580 var entry = {
580 var levelStr = this.colorizer.colorize('[' + level + ']', this.logStyles[level]);
581 this.echo(levelStr + ' [' + space + '] ' + message); // direct output
582 }
583 this.result.log.push({
584 level: level, 581 level: level,
585 space: space, 582 space: space,
586 message: message, 583 message: message,
587 date: new Date().toString() 584 date: new Date().toString()
588 }); 585 };
586 if (level in this.logFormats && isType(this.logFormats[level], "function")) {
587 message = this.logFormats[level](message, level, space);
588 } else {
589 var levelStr = this.colorizer.colorize('[' + level + ']', this.logStyles[level]);
590 message = levelStr + ' [' + space + '] ' + message;
591 }
592 if (this.options.verbose) {
593 this.echo(message); // direct output
594 }
595 this.result.log.push(entry);
589 return this; 596 return this;
590 }, 597 },
591 598
......