logs
This commit is contained in:
parent
5aca98fc58
commit
d76d5ed50d
|
|
@ -305,10 +305,19 @@ const AppDetail = ({ app }: { app: App }) => (
|
||||||
<Section>
|
<Section>
|
||||||
<SectionTitle>Logs</SectionTitle>
|
<SectionTitle>Logs</SectionTitle>
|
||||||
<LogsContainer>
|
<LogsContainer>
|
||||||
<LogLine>
|
{app.logs?.length ? (
|
||||||
<LogTime>--:--:--</LogTime>
|
app.logs.map((line, i) => (
|
||||||
<span style={{ color: '#666' }}>No logs yet</span>
|
<LogLine key={i}>
|
||||||
</LogLine>
|
<LogTime>{new Date(line.time).toLocaleTimeString()}</LogTime>
|
||||||
|
<span>{line.text}</span>
|
||||||
|
</LogLine>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<LogLine>
|
||||||
|
<LogTime>--:--:--</LogTime>
|
||||||
|
<span style={{ color: '#666' }}>No logs yet</span>
|
||||||
|
</LogLine>
|
||||||
|
)}
|
||||||
</LogsContainer>
|
</LogsContainer>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import type { Subprocess } from 'bun'
|
import type { Subprocess } from 'bun'
|
||||||
import { existsSync, readdirSync, readFileSync, watch } from 'fs'
|
import { existsSync, readdirSync, readFileSync, watch } from 'fs'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import type { App as SharedApp, AppState } from '../shared/types'
|
import type { App as SharedApp, AppState, LogLine } from '../shared/types'
|
||||||
|
|
||||||
export type { AppState } from '../shared/types'
|
export type { AppState } from '../shared/types'
|
||||||
|
|
||||||
const APPS_DIR = join(process.env.DATA_DIR ?? '.', 'apps')
|
const APPS_DIR = join(process.env.DATA_DIR ?? '.', 'apps')
|
||||||
|
const MAX_LOGS = 100
|
||||||
|
|
||||||
export type App = SharedApp & {
|
export type App = SharedApp & {
|
||||||
proc?: Subprocess
|
proc?: Subprocess
|
||||||
|
|
@ -96,6 +97,7 @@ const runApp = async (dir: string, port: number) => {
|
||||||
// Set state to starting
|
// Set state to starting
|
||||||
app.state = 'starting'
|
app.state = 'starting'
|
||||||
app.port = port
|
app.port = port
|
||||||
|
app.logs = []
|
||||||
update()
|
update()
|
||||||
|
|
||||||
const cwd = join(APPS_DIR, dir)
|
const cwd = join(APPS_DIR, dir)
|
||||||
|
|
@ -130,6 +132,9 @@ const runApp = async (dir: string, port: number) => {
|
||||||
const text = decoder.decode(value).trimEnd()
|
const text = decoder.decode(value).trimEnd()
|
||||||
if (text) {
|
if (text) {
|
||||||
log(dir, text)
|
log(dir, text)
|
||||||
|
const line: LogLine = { time: Date.now(), text }
|
||||||
|
app.logs = [...(app.logs ?? []).slice(-(MAX_LOGS - 1)), line]
|
||||||
|
update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@ app.get('/api/apps/stream', c => {
|
||||||
start(controller) {
|
start(controller) {
|
||||||
const send = () => {
|
const send = () => {
|
||||||
// Strip proc field from apps before sending
|
// Strip proc field from apps before sending
|
||||||
const apps: SharedApp[] = allApps().map(({ name, state, port, started }) => ({
|
const apps: SharedApp[] = allApps().map(({ name, state, port, started, logs }) => ({
|
||||||
name,
|
name,
|
||||||
state,
|
state,
|
||||||
port,
|
port,
|
||||||
started,
|
started,
|
||||||
|
logs,
|
||||||
}))
|
}))
|
||||||
const data = JSON.stringify(apps)
|
const data = JSON.stringify(apps)
|
||||||
controller.enqueue(encoder.encode(`data: ${data}\n\n`))
|
controller.enqueue(encoder.encode(`data: ${data}\n\n`))
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
export type AppState = 'invalid' | 'stopped' | 'starting' | 'running' | 'stopping'
|
export type AppState = 'invalid' | 'stopped' | 'starting' | 'running' | 'stopping'
|
||||||
|
|
||||||
|
export type LogLine = {
|
||||||
|
time: number
|
||||||
|
text: string
|
||||||
|
}
|
||||||
|
|
||||||
export type App = {
|
export type App = {
|
||||||
name: string
|
name: string
|
||||||
state: AppState
|
state: AppState
|
||||||
port?: number
|
port?: number
|
||||||
started?: number
|
started?: number
|
||||||
|
logs?: LogLine[]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user