Skip to content

Commit

Permalink
feat: highlight search log keywords (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePrometheus authored Jun 2, 2024
1 parent 065337c commit 5419a69
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/locales/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const msg = {
viewLogs: "View Logs",
logsTagsTip: `Only tags defined in the core/default/searchableLogsTags are searchable.
Check more details on the Configuration Vocabulary page`,
keywordsOfContentLogTips: "Current storage of SkyWalking OAP server does not support this.",
keywordsOfContentLogTips: "Current storage of SkyWalking OAP server does not support this",
setEvent: "Set Event",
viewAttributes: "View",
attributes: "Attributes",
Expand Down Expand Up @@ -355,7 +355,7 @@ const msg = {
addKeywordsOfContent: "Please input a keyword of content",
addExcludingKeywordsOfContent: "Please input a keyword of excluding content",
noticeTag: "Please press Enter after inputting a tag(key=value).",
conditionNotice: "Notice: Please press Enter after inputting a key of content, exclude key of content(key=value).",
conditionNotice: "Notice: Please press Enter after inputting a key of content, exclude key of content(key=value)",
language: "Language",
save: "Save",
editStrategy: "Edit Policies",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/lang/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const msg = {
viewLogs: "Ver Registro de Datos",
logsTagsTip: `Solamente etiquetas definidas en core/default/searchableLogsTags pueden ser buscadas.
Más información en la página de Vocabulario de Configuración`,
keywordsOfContentLogTips: "El almacenamiento actual del servidor SkyWalking OAP no lo soporta.",
keywordsOfContentLogTips: "El almacenamiento actual del servidor SkyWalking OAP no lo soporta",
setEvent: "Establecer Evento",
viewAttributes: "Ver",
serviceEvents: "Eventos Servico",
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const logStore = defineStore({
setLogCondition(data: Recordable) {
this.conditions = { ...this.conditions, ...data };
},
getLogKeywords() {
return this.conditions.keywordsOfContent;
},
resetState() {
this.logs = [];
this.conditions = {
Expand Down
84 changes: 44 additions & 40 deletions src/views/dashboard/related/log/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,51 +67,55 @@ limitations under the License. -->
</div>
<ConditionTags :type="'LOG'" @update="updateTags" />
</div>
<div class="row tips" v-show="!isBrowser">
<b>{{ t("conditionNotice") }}</b>
</div>
<div class="flex-h" v-show="!isBrowser">
<div class="mr-5" v-show="logStore.supportQueryLogsByKeywords">
<span class="mr-5 grey">{{ t("keywordsOfContent") }}:</span>
<span class="log-tags">
<span class="selected" v-for="(item, index) in keywordsOfContent" :key="`keywordsOfContent${index}`">
<span>{{ item }}</span>
<span class="remove-icon" @click="removeContent(index)">×</span>
</span>
</span>
<el-input
size="small"
class="inputs-max"
:placeholder="t('addKeywordsOfContent')"
v-model="contentStr"
@change="addLabels('keywordsOfContent')"
/>
</div>
<div class="mr-5" v-show="logStore.supportQueryLogsByKeywords">
<span class="grey mr-5"> {{ t("excludingKeywordsOfContent") }}: </span>
<span class="log-tags">
<span
class="selected"
v-for="(item, index) in excludingKeywordsOfContent"
:key="`excludingKeywordsOfContent${index}`"
>
<span>{{ item }}</span>
<span class="remove-icon" @click="removeExcludeContent(index)"> × </span>
</span>
</span>
<el-input
class="inputs-max"
size="small"
:placeholder="t('addExcludingKeywordsOfContent')"
v-model="excludingContentStr"
@change="addLabels('excludingKeywordsOfContent')"
/>
<div v-show="!isBrowser">
<div class="row tips">
<b>{{ t("conditionNotice") }}</b>
<el-tooltip :content="t('keywordsOfContentLogTips')">
<span v-show="!logStore.supportQueryLogsByKeywords">
<Icon iconName="help" class="mr-5" />
<Icon iconName="help" />
</span>
</el-tooltip>
</div>
<div v-show="logStore.supportQueryLogsByKeywords">
<div class="flex-h">
<div class="mr-5">
<span class="mr-5 grey">{{ t("keywordsOfContent") }}:</span>
<span class="log-tags">
<span class="selected" v-for="(item, index) in keywordsOfContent" :key="`keywordsOfContent${index}`">
<span>{{ item }}</span>
<span class="remove-icon" @click="removeContent(index)">×</span>
</span>
</span>
<el-input
size="small"
class="inputs-max"
:placeholder="t('addKeywordsOfContent')"
v-model="contentStr"
@change="addLabels('keywordsOfContent')"
/>
</div>
<div class="mr-5">
<span class="grey mr-5"> {{ t("excludingKeywordsOfContent") }}: </span>
<span class="log-tags">
<span
class="selected"
v-for="(item, index) in excludingKeywordsOfContent"
:key="`excludingKeywordsOfContent${index}`"
>
<span>{{ item }}</span>
<span class="remove-icon" @click="removeExcludeContent(index)"> × </span>
</span>
</span>
<el-input
class="inputs-max"
size="small"
:placeholder="t('addExcludingKeywordsOfContent')"
v-model="excludingContentStr"
@change="addLabels('excludingKeywordsOfContent')"
/>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/related/log/LogTable/LogBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ limitations under the License. -->
import { BrowserLogConstants } from "./data";
import { dateFormat } from "@/utils/dateFormat";
/*global defineProps, defineEmits, NodeListOf */
/* global defineProps, defineEmits */
const props = defineProps({
data: { type: Object as any, default: () => ({}) },
});
Expand Down
9 changes: 8 additions & 1 deletion src/views/dashboard/related/log/LogTable/LogService.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ limitations under the License. -->
<Icon iconName="merge" />
</el-tooltip>
</span>
<span v-else>{{ data[item.label] }}</span>
<span v-else v-html="highlightKeywords(data[item.label])"></span>
</div>
</div>
</template>
Expand All @@ -42,6 +42,8 @@ limitations under the License. -->
import type { LayoutConfig } from "@/types/dashboard";
import { dateFormat } from "@/utils/dateFormat";
import { WidgetType } from "@/views/dashboard/data";
import { useLogStore } from "@/store/modules/log";
const logStore = useLogStore();
/*global defineProps, defineEmits, Recordable */
const props = defineProps({
Expand All @@ -58,6 +60,11 @@ limitations under the License. -->
}
return (props.data.tags.find((d: { key: string; value: string }) => d.key === "level") || {}).value || "";
});
const highlightKeywords = (data: string) => {
const keywords = Object.values(logStore.getLogKeywords());
const regex = new RegExp(keywords.join("|"), "gi");
return data.replace(regex, (match) => `<span style="color: red">${match}</span>`);
};
function selectLog(label: string, value: string) {
if (label === "traceId") {
Expand Down

0 comments on commit 5419a69

Please sign in to comment.