mirror of
https://github.com/knadh/listmonk.git
synced 2025-10-30 02:25:55 +08:00
Refactor log line view to prevent HTML render log lines.
This commit processes log lis and renders them as different fields removing the use of <pre> and also `v-html` which renders HTML strings from log lines.
This commit is contained in:
parent
e54c33e8e8
commit
69f84c99d0
2 changed files with 35 additions and 7 deletions
|
|
@ -628,11 +628,22 @@ section.campaign {
|
||||||
.lines {
|
.lines {
|
||||||
height: 70vh;
|
height: 70vh;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 0.90rem;
|
||||||
|
|
||||||
.stamp {
|
padding: 15px;
|
||||||
|
border: 1px solid $grey-lightest;
|
||||||
|
|
||||||
|
.line {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timestamp {
|
||||||
color: $primary;
|
color: $primary;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: 160px;
|
min-width: 175px;
|
||||||
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.line:hover {
|
.line:hover {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
<template>
|
<template>
|
||||||
<section class="log-view">
|
<section class="log-view">
|
||||||
<b-loading :active="loading" :is-full-page="false" />
|
<b-loading :active="loading" :is-full-page="false" />
|
||||||
<pre class="lines" ref="lines">
|
<div class="lines" ref="lines">
|
||||||
<template v-for="(l, i) in lines"><span v-html="formatLine(l)" :key="i" class="line"></span>
|
<template v-for="(l, i) in lines">
|
||||||
</template></pre>
|
<span :set="line = splitLine(l)" :key="i" class="line">
|
||||||
|
<span class="timestamp" :title="line.file">{{ line.timestamp }}</span>
|
||||||
|
<span class="message">{{ line.message }}</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const reFormatLine = new RegExp(/^(.*) (.+?)\.go:[0-9]+:\s/g);
|
// Regexp for splitting log lines in the following format to
|
||||||
|
// [timestamp] [file] [message].
|
||||||
|
// 2021/05/01 00:00:00 init.go:99: reading config: config.toml
|
||||||
|
const reFormatLine = new RegExp(/^([0-9\s:/]+) (.+?\.go:[0-9]+):\s/g);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'LogView',
|
name: 'LogView',
|
||||||
|
|
@ -23,6 +31,15 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
splitLine: (l) => {
|
||||||
|
const parts = l.split(reFormatLine);
|
||||||
|
return {
|
||||||
|
timestamp: parts[1],
|
||||||
|
file: parts[2],
|
||||||
|
message: parts[3],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
formatLine: (l) => l.replace(reFormatLine, '<span class="stamp">$1</span> '),
|
formatLine: (l) => l.replace(reFormatLine, '<span class="stamp">$1</span> '),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue