Skip to content

Commit

Permalink
update: optimize mockConsole method
Browse files Browse the repository at this point in the history
  • Loading branch information
mirreal authored and yran committed Jun 20, 2017
1 parent 2bf5c3f commit 24c280b
Showing 1 changed file with 14 additions and 38 deletions.
52 changes: 14 additions & 38 deletions src/log/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class VConsoleLogTab extends VConsolePlugin {
that.isInBottom = false;
}
});

for (let i=0; i<that.logList.length; i++) {
that.printLog(that.logList[i]);
}
Expand Down Expand Up @@ -187,46 +187,22 @@ class VConsoleLogTab extends VConsolePlugin {
* @private
*/
mockConsole() {
let that = this;
const methodList = ['log', 'info', 'warn', 'debug', 'error'];

if (!window.console) {
window.console = {};
} else {
this.console.log = window.console.log;
this.console.info = window.console.info;
this.console.warn = window.console.warn;
this.console.debug = window.console.debug;
this.console.error = window.console.error;
methodList.map(method => this.console[method] = window.console[method]);
}
window.console.log = function() {
that.printLog({
logType: 'log',
logs: arguments
});
};
window.console.info = function() {
that.printLog({
logType: 'info',
logs: arguments
});
};
window.console.warn = function() {
that.printLog({
logType: 'warn',
logs: arguments
});
};
window.console.debug = function() {
that.printLog({
logType: 'debug',
logs: arguments
});
};
window.console.error = function() {
that.printLog({
logType: 'error',
logs: arguments
});
};

methodList.map(method => {
window.console[method] = (...args) => {
this.printLog({
logType: method,
logs: args
});
};
});
}

clearLog() {
Expand Down Expand Up @@ -494,4 +470,4 @@ class VConsoleLogTab extends VConsolePlugin {
} // END class


export default VConsoleLogTab;
export default VConsoleLogTab;

0 comments on commit 24c280b

Please sign in to comment.