All checks were successful
ci/woodpecker/push/push Pipeline was successful
Co-authored-by: Madison Grubb <madison@elastiflow.com> Reviewed-on: #4
12 lines
542 B
JavaScript
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 }
|
|
})
|