mirror of
https://github.com/liriliri/eruda.git
synced 2026-05-20 08:47:20 +08:00
fix(log): extra info from
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
{{#if displayHeader}}
|
{{#if headers}}
|
||||||
<div {{{class 'header'}}}>
|
<div {{{class 'header'}}}>
|
||||||
{{#repeat group.indentLevel}}
|
{{#repeat group.indentLevel}}
|
||||||
<div {{{class 'nesting-level'}}}></div>
|
<div {{{class 'nesting-level'}}}></div>
|
||||||
{{/repeat}}
|
{{/repeat}}
|
||||||
<div {{{class 'time-container'}}}>
|
<div {{{class 'time-container'}}}>
|
||||||
<span>{{time}}</span> <span>{{from}}</span>
|
<span>{{headers.time}}</span> <span>{{headers.from}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
isPrimitive,
|
isPrimitive,
|
||||||
wrap,
|
wrap,
|
||||||
defaults,
|
defaults,
|
||||||
dateFormat,
|
|
||||||
getObjType,
|
getObjType,
|
||||||
isEl,
|
isEl,
|
||||||
toStr,
|
toStr,
|
||||||
@@ -48,7 +47,7 @@ export default class Log extends Emitter {
|
|||||||
id,
|
id,
|
||||||
group = {},
|
group = {},
|
||||||
targetGroup = {},
|
targetGroup = {},
|
||||||
displayHeader = false,
|
headers,
|
||||||
ignoreFilter = false
|
ignoreFilter = false
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
@@ -59,7 +58,7 @@ export default class Log extends Emitter {
|
|||||||
this.args = args
|
this.args = args
|
||||||
this.count = 1
|
this.count = 1
|
||||||
this.id = id
|
this.id = id
|
||||||
this.displayHeader = displayHeader
|
this.headers = headers
|
||||||
this.ignoreFilter = ignoreFilter
|
this.ignoreFilter = ignoreFilter
|
||||||
this.collapsed = false
|
this.collapsed = false
|
||||||
this.el = document.createElement('li')
|
this.el = document.createElement('li')
|
||||||
@@ -68,11 +67,6 @@ export default class Log extends Emitter {
|
|||||||
this.width = 0
|
this.width = 0
|
||||||
this._$el = $(this.el)
|
this._$el = $(this.el)
|
||||||
|
|
||||||
if (displayHeader) {
|
|
||||||
this.time = getCurTime()
|
|
||||||
this.from = getFrom()
|
|
||||||
}
|
|
||||||
|
|
||||||
this._formatMsg()
|
this._formatMsg()
|
||||||
|
|
||||||
if (this.group) {
|
if (this.group) {
|
||||||
@@ -242,7 +236,7 @@ export default class Log extends Emitter {
|
|||||||
}
|
}
|
||||||
_formatMsg() {
|
_formatMsg() {
|
||||||
let { args } = this
|
let { args } = this
|
||||||
const { type, id, displayHeader, time, from, group } = this
|
const { type, id, headers, group } = this
|
||||||
|
|
||||||
// Don't change original args for lazy evaluation.
|
// Don't change original args for lazy evaluation.
|
||||||
args = clone(args)
|
args = clone(args)
|
||||||
@@ -320,7 +314,7 @@ export default class Log extends Emitter {
|
|||||||
return `<a href="${url}" target="_blank">${url}</a>`
|
return `<a href="${url}" target="_blank">${url}</a>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
msg = render({ msg, type, icon, id, displayHeader, time, from, group })
|
msg = render({ msg, type, icon, id, headers, group })
|
||||||
|
|
||||||
this._$el.addClass('eruda-log-container').html(msg)
|
this._$el.addClass('eruda-log-container').html(msg)
|
||||||
this._$content = this._$el.find('.eruda-log-content')
|
this._$content = this._$el.find('.eruda-log-content')
|
||||||
@@ -562,24 +556,6 @@ function formatEl(val) {
|
|||||||
)}</pre>`
|
)}</pre>`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFrom() {
|
|
||||||
const e = new Error()
|
|
||||||
let ret = ''
|
|
||||||
const lines = e.stack ? e.stack.split('\n') : ''
|
|
||||||
|
|
||||||
for (let i = 0, len = lines.length; i < len; i++) {
|
|
||||||
ret = lines[i]
|
|
||||||
if (ret.indexOf('winConsole') > -1 && i < len - 1) {
|
|
||||||
ret = lines[i + 1]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCurTime = () => dateFormat('HH:MM:ss')
|
|
||||||
|
|
||||||
const tpl = require('./Log.hbs')
|
const tpl = require('./Log.hbs')
|
||||||
const render = data => tpl(data)
|
const render = data => tpl(data)
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ import {
|
|||||||
raf,
|
raf,
|
||||||
xpath,
|
xpath,
|
||||||
isHidden,
|
isHidden,
|
||||||
lowerCase
|
lowerCase,
|
||||||
|
dateFormat
|
||||||
} from '../lib/util'
|
} from '../lib/util'
|
||||||
import evalCss from '../lib/evalCss'
|
import evalCss from '../lib/evalCss'
|
||||||
|
|
||||||
@@ -300,16 +301,24 @@ export default class Logger extends Emitter {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
insert(type, args) {
|
insert(type, args) {
|
||||||
|
let headers
|
||||||
|
if (this._displayHeader) {
|
||||||
|
headers = {
|
||||||
|
time: getCurTime(),
|
||||||
|
from: getFrom()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._asyncRender
|
this._asyncRender
|
||||||
? this.insertAsync(type, args)
|
? this.insertAsync(type, args, headers)
|
||||||
: this.insertSync(type, args)
|
: this.insertSync(type, args, headers)
|
||||||
}
|
}
|
||||||
insertAsync(type, args) {
|
insertAsync(type, args, headers) {
|
||||||
this._asyncList.push([type, args])
|
this._asyncList.push([type, args, headers])
|
||||||
|
|
||||||
this._handleAsyncList()
|
this._handleAsyncList()
|
||||||
}
|
}
|
||||||
insertSync(type, args) {
|
insertSync(type, args, headers) {
|
||||||
const logs = this._logs
|
const logs = this._logs
|
||||||
const groupStack = this._groupStack
|
const groupStack = this._groupStack
|
||||||
|
|
||||||
@@ -327,7 +336,7 @@ export default class Logger extends Emitter {
|
|||||||
}
|
}
|
||||||
extend(options, {
|
extend(options, {
|
||||||
id: ++id,
|
id: ++id,
|
||||||
displayHeader: this._displayHeader
|
headers
|
||||||
})
|
})
|
||||||
|
|
||||||
if (options.type === 'group' || options.type === 'groupCollapsed') {
|
if (options.type === 'group' || options.type === 'groupCollapsed') {
|
||||||
@@ -494,8 +503,8 @@ export default class Logger extends Emitter {
|
|||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
for (let i = 0; i < num; i++) {
|
for (let i = 0; i < num; i++) {
|
||||||
const [type, args] = asyncList.shift()
|
const [type, args, headers] = asyncList.shift()
|
||||||
this.insertSync(type, args)
|
this.insertSync(type, args, headers)
|
||||||
}
|
}
|
||||||
if (!done) raf(() => this._handleAsyncList(timeout))
|
if (!done) raf(() => this._handleAsyncList(timeout))
|
||||||
}, timeout)
|
}, timeout)
|
||||||
@@ -700,3 +709,21 @@ export default class Logger extends Emitter {
|
|||||||
this._ignoreScroll = true
|
this._ignoreScroll = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getCurTime = () => dateFormat('HH:MM:ss')
|
||||||
|
|
||||||
|
function getFrom() {
|
||||||
|
const e = new Error()
|
||||||
|
let ret = ''
|
||||||
|
const lines = e.stack ? e.stack.split('\n') : ''
|
||||||
|
|
||||||
|
for (let i = 0, len = lines.length; i < len; i++) {
|
||||||
|
ret = lines[i]
|
||||||
|
if (ret.indexOf('winConsole') > -1 && i < len - 1) {
|
||||||
|
ret = lines[i + 1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user