Skip to content

Commit bd7f6bc

Browse files
authored
feat: adds show hostname and container name to dropdown in mutli log mode (#3406)
1 parent 7ee2603 commit bd7f6bc

File tree

17 files changed

+79
-42
lines changed

17 files changed

+79
-42
lines changed

assets/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ declare module 'vue' {
9595
'Ph:stack': typeof import('~icons/ph/stack')['default']
9696
'Ph:stackSimple': typeof import('~icons/ph/stack-simple')['default']
9797
Popup: typeof import('./components/Popup.vue')['default']
98+
RandomColorTag: typeof import('./components/LogViewer/RandomColorTag.vue')['default']
9899
Releases: typeof import('./components/Releases.vue')['default']
99100
RouterLink: typeof import('vue-router')['RouterLink']
100101
RouterView: typeof import('vue-router')['RouterView']

assets/components/ContainerViewer/ContainerLog.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
:stream-source="useContainerStream"
1818
:entity="container"
1919
:visible-keys="visibleKeys"
20-
:show-container-name="false"
2120
/>
2221
</template>
2322
</ScrollableView>
@@ -46,5 +45,8 @@ const container = store.currentContainer(toRef(() => id));
4645
const visibleKeys = persistentVisibleKeysForContainer(container);
4746
const viewer = useTemplateRef<ComponentExposed<typeof ViewerWithSource>>("viewer");
4847
49-
provideLoggingContext(toRef(() => [container.value]));
48+
provideLoggingContext(
49+
toRef(() => [container.value]),
50+
{ showContainerName: false, showHostname: false },
51+
);
5052
</script>

assets/components/GroupedViewer/GroupedLog.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
:stream-source="useGroupedStream"
1818
:entity="group"
1919
:visible-keys="new Map<string[], boolean>()"
20-
:show-container-name="true"
2120
/>
2221
</template>
2322
</ScrollableView>
@@ -43,5 +42,8 @@ const { customGroups } = storeToRefs(swarmStore);
4342
4443
const group = computed(() => customGroups.value.find((g) => g.name === name) ?? new GroupedContainers("", []));
4544
46-
provideLoggingContext(toRef(() => group.value.containers));
45+
provideLoggingContext(
46+
toRef(() => group.value.containers),
47+
{ showContainerName: true, showHostname: false },
48+
);
4749
</script>

assets/components/LogViewer/ComplexLogItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<LogItem :logEntry :showContainerName @click="showDrawer(LogDetails, { entry: logEntry })" class="clickable">
2+
<LogItem :logEntry @click="showDrawer(LogDetails, { entry: logEntry })" class="clickable">
33
<ul class="fields space-x-4">
44
<li v-for="(value, name) in validValues" :key="name">
55
<span class="text-light">{{ name }}=</span><span class="font-bold" v-if="value === null">&lt;null&gt;</span>
@@ -17,7 +17,7 @@ import stripAnsi from "strip-ansi";
1717
import { type ComplexLogEntry } from "@/models/LogEntry";
1818
import LogDetails from "./LogDetails.vue";
1919
20-
const { logEntry, showContainerName = false } = defineProps<{
20+
const { logEntry } = defineProps<{
2121
logEntry: ComplexLogEntry;
2222
showContainerName?: boolean;
2323
}>();

assets/components/LogViewer/LogItem.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
22
<div class="relative flex w-full items-start gap-x-2 group-[.compact]:items-stretch">
3-
<LogStd :std="logEntry.std" class="select-none" v-if="showStd" />
4-
<ContainerName class="shrink-0 select-none" :id="logEntry.containerID" v-if="showContainerName" />
5-
<LogDate :date="logEntry.date" v-if="showTimestamp" class="select-none" />
3+
<LogStd :std="logEntry.std" class="shrink-0 select-none" v-if="showStd" />
4+
<RandomColorTag class="shrink-0 select-none" :value="host.name" v-if="showHostname" />
5+
<RandomColorTag class="shrink-0 select-none" :value="container.name" v-if="showContainerName" />
6+
<LogDate :date="logEntry.date" v-if="showTimestamp" class="shrink-0 select-none" />
67
<LogLevel
78
class="flex select-none"
89
:level="logEntry.level"
@@ -14,10 +15,16 @@
1415
<script lang="ts" setup>
1516
import { LogEntry, SimpleLogEntry } from "@/models/LogEntry";
1617
17-
const { showContainerName = false, logEntry } = defineProps<{
18+
const { logEntry } = defineProps<{
1819
logEntry: LogEntry<any>;
19-
showContainerName?: boolean;
2020
}>();
21+
const { showHostname, showContainerName } = useLoggingContext();
22+
23+
const { currentContainer } = useContainerStore();
24+
const { hosts } = useHosts();
25+
26+
const container = currentContainer(toRef(() => logEntry.containerID));
27+
const host = computed(() => hosts.value[container.value.host]);
2128
</script>
2229
<style scoped lang="postcss">
2330
.log-wrapper :deep(a) {

assets/components/LogViewer/LogList.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:data-time="item.date.getTime()"
99
class="group/entry"
1010
>
11-
<component :is="item.getComponent()" :log-entry="item" :show-container-name="showContainerName" />
11+
<component :is="item.getComponent()" :log-entry="item" />
1212
</li>
1313
</ul>
1414
</template>
@@ -20,7 +20,6 @@ const { loading, progress, currentDate } = useScrollContext();
2020
2121
const { messages } = defineProps<{
2222
messages: LogEntry<string | JSONObject>[];
23-
showContainerName: boolean;
2423
}>();
2524
2625
watchEffect(() => {

assets/components/LogViewer/LogViewer.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<LogList :messages="visibleMessages" :show-container-name="showContainerName" />
2+
<LogList :messages="visibleMessages" />
33
</template>
44

55
<script lang="ts" setup>
@@ -8,7 +8,6 @@ import { type JSONObject, LogEntry } from "@/models/LogEntry";
88
const props = defineProps<{
99
messages: LogEntry<string | JSONObject>[];
1010
visibleKeys: Map<string[], boolean>;
11-
showContainerName: boolean;
1211
}>();
1312
1413
const { messages, visibleKeys } = toRefs(props);

assets/components/LogViewer/MultiContainerActionToolbar.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@
6060
{{ $t("toolbar.show", { std: "STDERR" }) }}
6161
</a>
6262
</li>
63+
<li class="line"></li>
64+
<li>
65+
<a @click="showHostname = !showHostname">
66+
<mdi:check class="w-4" v-if="showHostname" />
67+
<div v-else class="w-4"></div>
68+
{{ $t("toolbar.show-hostname") }}
69+
</a>
70+
</li>
71+
<li>
72+
<a @click="showContainerName = !showContainerName">
73+
<mdi:check class="w-4" v-if="showContainerName" />
74+
<div v-else class="w-4"></div>
75+
{{ $t("toolbar.show-container-name") }}
76+
</a>
77+
</li>
6378
</ul>
6479
</div>
6580
</template>
@@ -69,7 +84,7 @@ const { showSearch } = useSearchFilter();
6984
7085
const clear = defineEmit();
7186
72-
const { streamConfig } = useLoggingContext();
87+
const { streamConfig, showHostname, showContainerName } = useLoggingContext();
7388
</script>
7489

7590
<style scoped lang="postcss">

assets/components/LogViewer/ContainerName.vue renamed to assets/components/LogViewer/RandomColorTag.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="tag grid w-40 overflow-hidden rounded text-center text-sm text-white">
33
<div class="random-color col-start-1 row-start-1 brightness-75"></div>
4-
<div class="col-start-1 row-start-1 truncate px-2 brightness-100 [direction:rtl]">{{ containerNames[id] }}</div>
4+
<div class="col-start-1 row-start-1 truncate px-2 brightness-100 [direction:rtl]">{{ value }}</div>
55
</div>
66
</template>
77
<script lang="ts">
@@ -24,14 +24,11 @@ const colors = [
2424
] as const;
2525
</script>
2626
<script lang="ts" setup>
27-
const containerStore = useContainerStore();
28-
const { containerNames } = storeToRefs(containerStore);
29-
30-
const { id } = defineProps<{
31-
id: string;
27+
const { value } = defineProps<{
28+
value: string;
3229
}>();
3330
34-
const color = computed(() => colors[Math.abs(hashCode(id)) % colors.length]);
31+
const color = computed(() => colors[Math.abs(hashCode(value)) % colors.length]);
3532
</script>
3633

3734
<style lang="postcss" scoped>

assets/components/LogViewer/SimpleLogItem.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<LogItem :logEntry :showContainerName>
2+
<LogItem :logEntry>
33
<div
44
class="log-wrapper whitespace-pre-wrap [word-break:break-word] group-[.disable-wrap]:whitespace-nowrap"
55
v-html="linkify(colorize(logEntry.message))"
@@ -23,9 +23,8 @@ const ansiConvertor = new AnsiConvertor({
2323
bg: "oklch(var(--base-color))",
2424
});
2525
26-
const { showContainerName = false } = defineProps<{
26+
defineProps<{
2727
logEntry: SimpleLogEntry;
28-
showContainerName?: boolean;
2928
}>();
3029
3130
const colorize = (value: string) => ansiConvertor.toHtml(value);

0 commit comments

Comments
 (0)