Skip to content

Commit 7c94922

Browse files
committed
feat: added nginx log filter #35
1 parent 20daf83 commit 7c94922

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

frontend/src/views/nginx_log/NginxLog.vue

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import {useGettext} from 'vue3-gettext'
33
import ws from '@/lib/websocket'
4-
import {nextTick, onMounted, onUnmounted, reactive, ref, watch} from 'vue'
4+
import {computed, nextTick, onMounted, onUnmounted, reactive, ref, watch} from 'vue'
55
import ReconnectingWebSocket from 'reconnecting-websocket'
66
import {useRoute, useRouter} from 'vue-router'
77
import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
@@ -41,23 +41,26 @@ function openWs() {
4141
}
4242
4343
function addLog(data: string, prepend: boolean = false) {
44-
const para = document.createElement('p')
45-
para.appendChild(document.createTextNode(data.trim()))
46-
47-
const node = (logContainer.value as any as Node)
44+
// const para = document.createElement('p')
45+
// para.appendChild(document.createTextNode(data.trim()))
46+
//
47+
// const node = (logContainer.value as any as Node)
4848
4949
if (prepend) {
50-
node.insertBefore(para, node.firstChild)
50+
buffer.value = data + buffer.value
5151
} else {
52-
node.appendChild(para)
52+
buffer.value += data
5353
}
54+
5455
const elem = (logContainer.value as any as Element)
5556
elem.scroll({
5657
top: elem.scrollHeight,
5758
left: 0,
5859
})
5960
}
6061
62+
const buffer = ref('')
63+
6164
const page = ref(0)
6265
6366
function init() {
@@ -68,9 +71,7 @@ function init() {
6871
directive_idx: 0
6972
}).then(r => {
7073
page.value = r.page - 1
71-
r.content.split('\n').forEach((v: string) => {
72-
addLog(v)
73-
})
74+
addLog(r.content)
7475
})
7576
}
7677
@@ -130,9 +131,7 @@ function on_scroll_log() {
130131
directive_idx: 0
131132
}).then(r => {
132133
page.value = r.page - 1
133-
r.content.split('\n').forEach((v: string) => {
134-
addLog(v, true)
135-
})
134+
addLog(r.content, true)
136135
}).finally(() => {
137136
loading.value = false
138137
})
@@ -142,6 +141,14 @@ function on_scroll_log() {
142141
}
143142
}
144143
144+
const filter = ref('')
145+
146+
const computedBuffer = computed(() => {
147+
if (filter.value) {
148+
return buffer.value.split('\n').filter(line => line.match(filter.value)).join('\n')
149+
}
150+
return buffer.value
151+
})
145152
</script>
146153

147154
<template>
@@ -150,11 +157,14 @@ function on_scroll_log() {
150157
<a-form-item :label="$gettext('Auto Refresh')">
151158
<a-switch v-model:checked="auto_refresh"/>
152159
</a-form-item>
160+
<a-form-item :label="$gettext('Filter')">
161+
<a-input v-model:value="filter" style="max-width: 300px"/>
162+
</a-form-item>
153163
</a-form>
154164

155165
<a-card>
156166
<pre class="nginx-log-container" ref="logContainer"
157-
@scroll="debounce(on_scroll_log,100, null)()"></pre>
167+
@scroll="debounce(on_scroll_log,100, null)()" v-html="computedBuffer"/>
158168
</a-card>
159169
</a-card>
160170
<footer-tool-bar v-if="control.type==='site'">
@@ -171,9 +181,7 @@ function on_scroll_log() {
171181
padding: 5px;
172182
margin-bottom: 0;
173183
174-
p {
175-
font-size: 12px;
176-
line-height: 1;
177-
}
184+
font-size: 12px;
185+
line-height: 2;
178186
}
179187
</style>

server/api/nginx_log.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ func handleLogControl(ws *websocket.Conn, controlChan chan controlStruct, errCha
228228
defer func() {
229229
if err := recover(); err != nil {
230230
log.Println("tailNginxLog recovery", err)
231-
_ = ws.WriteMessage(websocket.TextMessage, err.([]byte))
232231
return
233232
}
234233
}()

0 commit comments

Comments
 (0)