From e2354b85286007ea31f523c7126408607cfa12de Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:54:59 +0800 Subject: [PATCH] feat(log): Add Highlighting to Logs (#7707) --- agent/app/service/container.go | 2 +- .../src/components/container-log/index.vue | 41 +++- frontend/src/components/hightlight/index.vue | 220 ++++++++++++++++++ frontend/src/components/log-file/index.vue | 12 +- frontend/src/components/task-log/index.vue | 1 + frontend/src/views/log/system/index.vue | 1 + frontend/src/views/log/website/index.vue | 1 + .../website/config/log/log-fiile/index.vue | 10 +- 8 files changed, 271 insertions(+), 17 deletions(-) create mode 100644 frontend/src/components/hightlight/index.vue diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 28d57762e..9f391504f 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -834,7 +834,7 @@ func collectLogs(params dto.StreamLog, messageChan chan<- string, errorChan chan if params.Follow { cmdArgs = append(cmdArgs, "-f") } - if params.Tail != "all" { + if params.Tail != "0" { cmdArgs = append(cmdArgs, "--tail", params.Tail) } if params.Since != "all" { diff --git a/frontend/src/components/container-log/index.vue b/frontend/src/components/container-log/index.vue index 4a93108b5..d1682143a 100644 --- a/frontend/src/components/container-log/index.vue +++ b/frontend/src/components/container-log/index.vue @@ -24,20 +24,26 @@ {{ $t('commons.button.clean') }} -
+ + +
+
+
+ +
@@ -48,6 +54,7 @@ import { dateFormatForName } from '@/utils/util'; import { onUnmounted, reactive, ref } from 'vue'; import { ElMessageBox } from 'element-plus'; import { MsgError, MsgSuccess } from '@/utils/message'; +import hightlight from '@/components/hightlight/index.vue'; const props = defineProps({ container: { @@ -71,6 +78,15 @@ const logSearch = reactive({ tail: 100, compose: '', }); +const logHeight = 20; +const logCount = ref(0); +const totalHeight = computed(() => logHeight * logCount.value); +const startIndex = ref(0); +const containerHeight = ref(500); +const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight)); +const visibleLogs = computed(() => { + return logs.value.slice(startIndex.value, startIndex.value + visibleCount.value); +}); const timeOptions = ref([ { label: i18n.global.t('container.all'), value: 'all' }, @@ -178,6 +194,13 @@ onMounted(() => { logSearch.mode = 'all'; logSearch.isWatch = true; + nextTick(() => { + if (logContainer.value) { + logContainer.value.scrollTop = totalHeight.value; + containerHeight.value = logContainer.value.getBoundingClientRect().height; + } + }); + searchLogs(); }); diff --git a/frontend/src/components/hightlight/index.vue b/frontend/src/components/hightlight/index.vue new file mode 100644 index 000000000..4535ae404 --- /dev/null +++ b/frontend/src/components/hightlight/index.vue @@ -0,0 +1,220 @@ + + + + diff --git a/frontend/src/components/log-file/index.vue b/frontend/src/components/log-file/index.vue index 2c40c6210..024a43f50 100644 --- a/frontend/src/components/log-file/index.vue +++ b/frontend/src/components/log-file/index.vue @@ -25,7 +25,7 @@ class="log-item" :style="{ top: `${(startIndex + index) * logHeight}px` }" > - {{ log }} +
@@ -36,6 +36,7 @@ import { downloadFile } from '@/utils/util'; import { ReadByLine } from '@/api/modules/files'; import { GlobalStore } from '@/store'; import bus from '@/global/bus'; +import hightlight from '@/components/hightlight/index.vue'; const globalStore = GlobalStore(); interface LogProps { @@ -44,6 +45,7 @@ interface LogProps { name?: string; tail?: boolean; taskID?: string; + colorMode?: string; } const props = defineProps({ @@ -54,6 +56,7 @@ const props = defineProps({ type: '', name: '', tail: false, + colorMode: 'nginx', }), }, defaultButton: { @@ -315,7 +318,7 @@ defineExpose({ changeTail, onDownload, clearLog }); diff --git a/frontend/src/components/task-log/index.vue b/frontend/src/components/task-log/index.vue index d8f2af0fd..69d5934ef 100644 --- a/frontend/src/components/task-log/index.vue +++ b/frontend/src/components/task-log/index.vue @@ -39,6 +39,7 @@ const config = reactive({ resourceID: 0, taskType: '', tail: true, + colorMode: 'task', }); const open = ref(false); const showTail = ref(true); diff --git a/frontend/src/views/log/system/index.vue b/frontend/src/views/log/system/index.vue index ea093dfdf..10c88770c 100644 --- a/frontend/src/views/log/system/index.vue +++ b/frontend/src/views/log/system/index.vue @@ -45,6 +45,7 @@ const hasContent = ref(false); const logConfig = reactive({ type: 'system', name: '', + colorMode: 'system', }); const showLog = ref(false); diff --git a/frontend/src/views/log/website/index.vue b/frontend/src/views/log/website/index.vue index 3a3e4db43..d18afcf9f 100644 --- a/frontend/src/views/log/website/index.vue +++ b/frontend/src/views/log/website/index.vue @@ -70,6 +70,7 @@ const logConfig = reactive({ type: 'website', id: undefined, name: 'access.log', + colorMode: 'nginx', }); const showLog = ref(false); const loading = ref(false); diff --git a/frontend/src/views/website/website/config/log/log-fiile/index.vue b/frontend/src/views/website/website/config/log/log-fiile/index.vue index 253424335..1fd5217a2 100644 --- a/frontend/src/views/website/website/config/log/log-fiile/index.vue +++ b/frontend/src/views/website/website/config/log/log-fiile/index.vue @@ -5,7 +5,7 @@ - +