forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
27 lines (21 loc) · 666 Bytes
/
logger.ts
File metadata and controls
27 lines (21 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { Context, Next } from "hono"
function nowIso(): string {
return new Date().toISOString()
}
export function requestLogger() {
return async function timestampedRequestLogger(
c: Context,
next: Next,
): Promise<void> {
const startTime = performance.now()
await next()
const durationMs = (performance.now() - startTime).toFixed(1)
const method = c.req.method
const path = c.req.path
const status = c.res.status
console.log(`[${nowIso()}] ${method} ${path} ${status} ${durationMs}ms`)
}
}
export function logError(message: string, error: unknown): void {
console.error(`[${nowIso()}] ${message}`, error)
}