dashboard: make log display more resilient

This commit is contained in:
Ben Allfree 2024-11-10 22:12:23 -08:00
parent e967d9ed45
commit 696d1e686a
2 changed files with 18 additions and 8 deletions

View File

@ -14,10 +14,10 @@ import {
type DeleteInstanceResult,
type InstanceFields,
type InstanceId,
type InstanceLogFields,
PocketBase,
RestCommands,
RestMethods,
type UntrustedInstanceLogFields,
type UpdateInstancePayload,
UpdateInstancePayloadSchema,
type UpdateInstanceResult,
@ -245,7 +245,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
const watchInstanceLog = (
instance: InstanceFields,
update: (log: InstanceLogFields) => void,
update: (log: UntrustedInstanceLogFields) => void,
nInitial = 100,
): (() => void) => {
const auth = client.authStore.exportToCookie()
@ -269,7 +269,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
}),
onmessage: (event) => {
const {} = event
const log = JSON.parse(event.data) as InstanceLogFields
const log = JSON.parse(event.data) as UntrustedInstanceLogFields
update(log)
},

View File

@ -30,9 +30,11 @@
// This will take in the log message and return either the message or a string
const logText = (log: any) => {
try {
return JSON.parse(log.message)
const parsed = JSON.parse(log.message)
// Split on newlines and join with <br> tags
return parsed.split('\n').join('<br>')
} catch (e) {
return log.message
return log.message.split('\n').join('<br>')
}
}
@ -80,7 +82,15 @@
logs.set([])
unwatch = client().watchInstanceLog($instance, (newLog) => {
logs.update((currentLogs) => {
return [...currentLogs, newLog]
return [
...currentLogs,
{
time: `<no time>`,
stream: StreamNames.StdOut,
message: `<no message>`,
...newLog,
},
]
})
})
})
@ -119,7 +129,7 @@
<div>
<span class="mr-1 text-accent">{log.time}</span>
<span class="mr-1 text-base-content {logColor(log.stream)}"
>{logText(log)}</span
>{@html logText(log)}</span
>
</div>
</div>
@ -149,7 +159,7 @@
<span class="mr-1 text-accent">{log.time}</span>
<span class="mr-1 text-base-content {logColor(log.stream)}"
>{logText(log)}</span
>{@html logText(log)}</span
>
</div>
</div>