Files
kestrelos/server/api/log.post.js
Madison Grubb 1668ec4230
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
heavily simplify server and app content. unify styling
2026-02-13 23:36:17 -05:00

12 lines
542 B
JavaScript

const CONSOLE_METHOD = Object.freeze({ error: 'error', warn: 'warn', info: 'log', debug: 'log' })
export default defineEventHandler(async (event) => {
const body = await readBody(event).catch(() => ({}))
const { level, message, data, sessionId, userId } = body
const prefix = `[CLIENT${sessionId ? `:${sessionId}` : ''}${userId ? `:${userId.slice(0, 8)}` : ''}]`
const msg = data ? `${message} ${JSON.stringify(data)}` : message
const method = CONSOLE_METHOD[level] || 'log'
console[method](prefix, msg)
return { ok: true }
})