2020-09-08 07:53:42 +00:00
|
|
|
const m = require('mithril')
|
|
|
|
const socket = require('../socket')
|
|
|
|
const Module = require('../module')
|
|
|
|
|
|
|
|
const Log = Module({
|
|
|
|
init: function() {
|
|
|
|
this.connected = socket.connected
|
|
|
|
this.loglines = []
|
2020-09-13 01:01:16 +00:00
|
|
|
this.logUpdated = false
|
2020-09-08 07:53:42 +00:00
|
|
|
|
|
|
|
this.on('newlog', data => {
|
|
|
|
this.loglines.push(this.formatLine(data))
|
2020-09-13 01:01:16 +00:00
|
|
|
this.logUpdated = true
|
2020-09-08 07:53:42 +00:00
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this._socketOn(() => this.loadData())
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function() {
|
|
|
|
socket.emit('core.unlistenlogs', {})
|
|
|
|
},
|
|
|
|
|
|
|
|
loadData: function() {
|
|
|
|
this.loglines = []
|
|
|
|
socket.emit('core.listenlogs', {})
|
|
|
|
socket.emit('core.getlastlogs', {}, (res) => {
|
|
|
|
this.loglines = res.map(this.formatLine)
|
2020-09-13 01:01:16 +00:00
|
|
|
this.logUpdated = true
|
2020-09-08 07:53:42 +00:00
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
formatLine: function(line) {
|
|
|
|
return m.trust(line.replace(/\\033\[37m/g, '<span class="white">')
|
|
|
|
.replace(/\\033\[33m/g, '<span class="yellow">')
|
|
|
|
.replace(/\\033\[36m/g, '<span class="cyan">')
|
|
|
|
.replace(/\\033\[35m/g, '<span class="magenta">')
|
|
|
|
.replace(/\\033\[31m/g, '<span class="red">')
|
|
|
|
.replace(/\\033\[7m/g, '<span class="inverse">')
|
|
|
|
.replace(/\\033\[32m/g, '<span class="green">')
|
|
|
|
.replace(/\\033\[27m/g, '</span>')
|
|
|
|
.replace(/\\033\[39m/g, '</span>'))
|
|
|
|
},
|
|
|
|
|
|
|
|
view: function() {
|
|
|
|
return [
|
|
|
|
m('h1.header', 'Log'),
|
2020-09-13 01:01:16 +00:00
|
|
|
m('div#logger', {
|
|
|
|
onupdate: (vnode) => {
|
|
|
|
if (this.logUpdated) {
|
|
|
|
vnode.dom.scrollTop = vnode.dom.scrollHeight
|
|
|
|
this.logUpdated = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [
|
2020-09-08 07:53:42 +00:00
|
|
|
this.loglines.map((line, i) => {
|
|
|
|
return m('div', { key: i }, line)
|
|
|
|
}),
|
|
|
|
m('div.padder'),
|
|
|
|
]),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = Log
|