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);

assets/components/LogViewer/ViewerWithSource.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<EventSource ref="source" #default="{ messages }" :stream-source="streamSource" :entity="entity">
3-
<LogViewer :messages="messages" :visible-keys="visibleKeys" :show-container-name="showContainerName" />
3+
<LogViewer :messages="messages" :visible-keys="visibleKeys" />
44
</EventSource>
55
</template>
66

@@ -9,10 +9,9 @@ import EventSource from "@/components/LogViewer/EventSource.vue";
99
import { LogStreamSource } from "@/composable/eventStreams";
1010
import { ComponentExposed } from "vue-component-type-helpers";
1111
12-
const { streamSource, visibleKeys, showContainerName, entity } = defineProps<{
12+
const { streamSource, visibleKeys, entity } = defineProps<{
1313
streamSource: (t: Ref<T>) => LogStreamSource;
1414
visibleKeys: Map<string[], boolean>;
15-
showContainerName: boolean;
1615
entity: T;
1716
}>();
1817

assets/components/LogViewer/__snapshots__/EventSource.spec.ts.snap

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`<ContainerEventSource /> > render html correctly > should render dates with 12 hour style 1`] = `
4-
"<ul data-v-cf9ff940="" class="events group pt-4 medium">
4+
"<ul data-v-cf9ff940="" class="events group pt-4 medium" show-container-name="false">
55
<li data-v-cf9ff940="" data-key="1" data-time="1560336942459" class="group/entry">
66
<div data-v-1344ff3d="" data-v-cf9ff940="" class="relative flex w-full items-start gap-x-2 group-[.compact]:items-stretch">
77
<!--v-if-->
88
<!--v-if-->
9-
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start select-none" size="small">
9+
<!--v-if-->
10+
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start shrink-0 select-none" size="small">
1011
<div class="inline-flex gap-2 whitespace-nowrap text-blue"><time datetime="2019-06-12T10:55:42.459Z" class="mobile-hidden">06/12/2019</time><time datetime="2019-06-12T10:55:42.459Z">10:55:42 AM</time></div>
1112
</div>
1213
<div data-v-e625cddd="" data-v-1344ff3d="" class="mt-1.5 size-2.5 flex-none rounded-lg flex select-none"></div>
@@ -20,12 +21,13 @@ exports[`<ContainerEventSource /> > render html correctly > should render dates
2021
`;
2122

2223
exports[`<ContainerEventSource /> > render html correctly > should render dates with 24 hour style 1`] = `
23-
"<ul data-v-cf9ff940="" class="events group pt-4 medium">
24+
"<ul data-v-cf9ff940="" class="events group pt-4 medium" show-container-name="false">
2425
<li data-v-cf9ff940="" data-key="1" data-time="1560336942459" class="group/entry">
2526
<div data-v-1344ff3d="" data-v-cf9ff940="" class="relative flex w-full items-start gap-x-2 group-[.compact]:items-stretch">
2627
<!--v-if-->
2728
<!--v-if-->
28-
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start select-none" size="small">
29+
<!--v-if-->
30+
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start shrink-0 select-none" size="small">
2931
<div class="inline-flex gap-2 whitespace-nowrap text-blue"><time datetime="2019-06-12T10:55:42.459Z" class="mobile-hidden">06/12/2019</time><time datetime="2019-06-12T10:55:42.459Z">10:55:42</time></div>
3032
</div>
3133
<div data-v-e625cddd="" data-v-1344ff3d="" class="mt-1.5 size-2.5 flex-none rounded-lg flex select-none"></div>
@@ -39,12 +41,13 @@ exports[`<ContainerEventSource /> > render html correctly > should render dates
3941
`;
4042

4143
exports[`<ContainerEventSource /> > render html correctly > should render messages 1`] = `
42-
"<ul data-v-cf9ff940="" class="events group pt-4 medium">
44+
"<ul data-v-cf9ff940="" class="events group pt-4 medium" show-container-name="false">
4345
<li data-v-cf9ff940="" data-key="1" data-time="1560336942459" class="group/entry">
4446
<div data-v-1344ff3d="" data-v-cf9ff940="" class="relative flex w-full items-start gap-x-2 group-[.compact]:items-stretch">
4547
<!--v-if-->
4648
<!--v-if-->
47-
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start select-none" size="small">
49+
<!--v-if-->
50+
<div data-v-961504e7="" data-v-1344ff3d="" class="tag inline-flex items-center justify-center rounded bg-base-lighter px-2 py-[0.2em] !items-start shrink-0 select-none" size="small">
4851
<div class="inline-flex gap-2 whitespace-nowrap text-blue"><time datetime="2019-06-12T10:55:42.459Z" class="mobile-hidden">06/12/2019</time><time datetime="2019-06-12T10:55:42.459Z">10:55:42 AM</time></div>
4952
</div>
5053
<div data-v-e625cddd="" data-v-1344ff3d="" class="mt-1.5 size-2.5 flex-none rounded-lg flex select-none"></div>

assets/components/MultiContainerViewer/MultiContainerLog.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
:stream-source="useMergedStream"
1818
:entity="containers"
1919
:visible-keys="new Map<string[], boolean>()"
20-
:show-container-name="true"
2120
/>
2221
</template>
2322
</ScrollableView>
@@ -37,5 +36,5 @@ const viewer = ref<ComponentExposed<typeof ViewerWithSource>>();
3736
const { allContainersById, ready } = storeToRefs(containerStore);
3837
const containers = computed(() => ids.map((id) => allContainersById.value[id]));
3938
40-
provideLoggingContext(containers);
39+
provideLoggingContext(containers, { showContainerName: true, showHostname: false });
4140
</script>

assets/components/ServiceViewer/ServiceLog.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
:stream-source="useServiceStream"
2121
:entity="service"
2222
:visible-keys="new Map<string[], boolean>()"
23-
:show-container-name="true"
2423
/>
2524
</template>
2625
</ScrollableView>
@@ -41,5 +40,8 @@ const store = useSwarmStore();
4140
const { services } = storeToRefs(store) as unknown as { services: Ref<Service[]> };
4241
const service = computed(() => services.value.find((s) => s.name === name) ?? new Service("", []));
4342
44-
provideLoggingContext(toRef(() => service.value.containers));
43+
provideLoggingContext(
44+
toRef(() => service.value.containers),
45+
{ showContainerName: true, showHostname: false },
46+
);
4547
</script>

assets/components/StackViewer/StackLog.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
:stream-source="useStackStream"
2424
:entity="stack"
2525
:visible-keys="new Map<string[], boolean>()"
26-
:show-container-name="true"
2726
/>
2827
</template>
2928
</ScrollableView>
@@ -42,5 +41,8 @@ const viewer = ref<ComponentExposed<typeof ViewerWithSource>>();
4241
const store = useSwarmStore();
4342
const { stacks } = storeToRefs(store) as unknown as { stacks: Ref<Stack[]> };
4443
const stack = computed(() => stacks.value.find((s) => s.name === name) ?? new Stack("", [], []));
45-
provideLoggingContext(toRef(() => stack.value.containers));
44+
provideLoggingContext(
45+
toRef(() => stack.value.containers),
46+
{ showContainerName: true, showHostname: false },
47+
);
4648
</script>

assets/composable/logContext.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type LogContext = {
77
loadingMore: boolean;
88
hasComplexLogs: boolean;
99
levels: Set<Level>;
10+
showContainerName: boolean;
11+
showHostname: boolean;
1012
};
1113

1214
export const allLevels: Level[] = [
@@ -27,7 +29,10 @@ const searchParams = new URLSearchParams(window.location.search);
2729
const stdout = searchParams.has("stdout") ? searchParams.get("stdout") === "true" : true;
2830
const stderr = searchParams.has("stderr") ? searchParams.get("stderr") === "true" : true;
2931

30-
export const provideLoggingContext = (containers: Ref<Container[]>) => {
32+
export const provideLoggingContext = (
33+
containers: Ref<Container[]>,
34+
{ showContainerName = false, showHostname = false } = {},
35+
) => {
3136
provide(
3237
loggingContextKey,
3338
reactive({
@@ -36,6 +41,8 @@ export const provideLoggingContext = (containers: Ref<Container[]>) => {
3641
loadingMore: false,
3742
hasComplexLogs: false,
3843
levels: new Set<Level>(allLevels),
44+
showContainerName,
45+
showHostname,
3946
}),
4047
);
4148
};
@@ -49,6 +56,8 @@ export const useLoggingContext = () => {
4956
loadingMore: false,
5057
hasComplexLogs: false,
5158
levels: new Set<Level>(allLevels),
59+
showContainerName: false,
60+
showHostname: false,
5261
}),
5362
);
5463

locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ toolbar:
77
stop: Stop
88
start: Start
99
restart: Restart
10+
show-hostname: Show hostname
11+
show-container-name: Show container name
1012
label:
1113
containers: Containers
1214
container: No containers | 1 container | {count} containers

0 commit comments

Comments
 (0)