From e4a821d9815d88f6fb26e0dd14f43609038c6734 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 14 Oct 2024 00:19:10 -0700 Subject: log usernames --- lib/app.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/app.ts b/lib/app.ts index 5adc104c..51b43d05 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -27,11 +27,20 @@ app.addHook("onRequest", async (req) => { }); app.addHook("onResponse", async (req, reply) => { + const rawCookies = req.raw.headers.cookie || ""; + + const cookies: any = rawCookies.split(";").reduce((acc, cookie) => { + const [key, value] = cookie.split("=").map((s) => s.trim()); + if (key && value) acc[key] = value; + return acc; + }, {}); + resLogger.info({ id: req.id, url: req.raw.url, statusCode: reply.raw.statusCode, durationMs: reply.elapsedTime, + username: cookies.username, }); }); -- cgit v1.2.3