feat(console): timeLog

This commit is contained in:
surunzi
2019-09-27 16:42:08 +08:00
parent 2e3a0bb795
commit 9fec5dda3c
4 changed files with 20 additions and 6 deletions

View File

@@ -313,6 +313,7 @@ const CONSOLE_METHOD = [
'warn',
'dir',
'time',
'timeLog',
'timeEnd',
'clear',
'table',

View File

@@ -112,18 +112,29 @@ export default class Logger extends Emitter {
return this.insert('table', args)
}
time(name = 'default') {
if (this._timer[name]) {
return this.insert('warn', [`Timer '${name}' already exists`])
}
this._timer[name] = perfNow()
return this
}
timeEnd(name = 'default') {
timeLog(name = 'default') {
const startTime = this._timer[name]
if (!startTime) return
delete this._timer[name]
if (!startTime) {
return this.insert('warn', [`Timer '${name}' does not exist`])
}
return this.info(`${name}: ${perfNow() - startTime}ms`)
}
timeEnd(name = 'default') {
this.timeLog(name)
delete this._timer[name]
return this
}
clear() {
this.silentClear()
@@ -135,6 +146,8 @@ export default class Logger extends Emitter {
silentClear() {
this._logs = []
this._lastLog = {}
this._count = {}
this._timer = {}
this._groupStack = new Stack()
return this.render()