toes logs

This commit is contained in:
Chris Wanstrath 2026-01-29 11:28:22 -08:00
parent 7763dc6314
commit e1b53fc54d
3 changed files with 40 additions and 2 deletions

View File

@ -25,7 +25,8 @@
[x] `toes stop <app>`
[x] `toes restart <app>`
[x] `toes open <app>`
[ ] `toes logs <app>`
[x] `toes logs <app>`
[x] `toes logs -f <app>`
[ ] `toes new`
[ ] `toes pull`
[ ] `toes push`

View File

@ -1,6 +1,6 @@
import { program } from 'commander'
import { join } from 'path'
import type { App } from '@types'
import type { App, LogLine } from '@types'
import { APPS_DIR } from '$apps'
const HOST = `http://localhost:${process.env.PORT ?? 3000}`
@ -57,6 +57,22 @@ const restartApp = async (app: string) => {
await post(`/api/apps/${app}/restart`)
}
async function logApp(name: string) {
const logs: LogLine[] | undefined = await get(`/api/apps/${name}/logs`)
if (!logs) {
console.error(`App not found: ${name}`)
return
}
if (logs.length === 0) {
console.log('No logs yet')
return
}
for (const line of logs) {
const time = new Date(line.time).toLocaleTimeString()
console.log(`${time} ${line.text}`)
}
}
async function openApp(name: string) {
const app: App | undefined = await get(`/api/apps/${name}`)
if (!app) {
@ -99,6 +115,17 @@ program
.argument('<name>', 'app name')
.action(restartApp)
program
.command('logs')
.description('Show logs for an app')
.argument('<name>', 'app name')
.action(logApp)
program
.command('log', { hidden: true })
.argument('<name>', 'app name')
.action(logApp)
program
.command('open')
.description('Open an app in browser')

View File

@ -70,6 +70,16 @@ app.get('/api/apps/:app', c => {
return c.json(convert(app))
})
app.get('/api/apps/:app/logs', c => {
const appName = c.req.param('app')
if (!appName) return c.json({ error: 'App not found' }, 404)
const app = allApps().find(a => a.name === appName)
if (!app) return c.json({ error: 'App not found' }, 404)
return c.json(app.logs ?? [])
})
app.post('/api/apps/:app/start', c => {
const appName = c.req.param('app')
if (!appName) return c.json({ error: 'App not found' }, 404)