From d1fe1252a106c0e09b24763a994f1d707156c649 Mon Sep 17 00:00:00 2001 From: zobweyt Date: Thu, 8 Aug 2024 20:47:46 +0300 Subject: [PATCH] Add better API logging --- frontend/src/lib/api/middleware.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/api/middleware.ts b/frontend/src/lib/api/middleware.ts index c95dda7..0ae9b81 100644 --- a/frontend/src/lib/api/middleware.ts +++ b/frontend/src/lib/api/middleware.ts @@ -1,4 +1,5 @@ import { type Middleware } from "openapi-fetch"; +import colors from "picocolors"; import { getSession, resetSession } from "~/lib/auth/session"; export const AUTH_MIDDLEWARE: Middleware = { @@ -19,6 +20,12 @@ export const AUTH_MIDDLEWARE: Middleware = { export const DEBUG_MIDDLEWARE: Middleware = { onResponse: (options) => { - console.debug(`${options.request.method} ${options.schemaPath} - ${options.response.status} ${options.response.statusText}`); + const timestamp = colors.dim(new Date().toLocaleTimeString()); + const prefix = colors.cyan(colors.bold("[api]")); + const method = colors.green(options.request.method); + const route = colors.dim(options.request.url); + const status = colors.yellow(`${options.response.status} ${options.response.statusText}`); + + console.debug(`${timestamp} ${prefix} ${method} ${route} ${status}`); }, };