Skip to content

Commit

Permalink
Route ID, etag, cache control
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Jan 16, 2025
1 parent 0f50487 commit 4299264
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function logRequest({ event, resolve }) {
const response = await resolve(event);

// logging happens after the response is generated
log(response.status, event);
log(event, response);
return response;
}

Expand Down
15 changes: 13 additions & 2 deletions src/lib/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ import type { RequestEvent } from "@sveltejs/kit";
* @param status
* @param event
*/
export function log(status: number, event: RequestEvent): void {
export function log(event: RequestEvent, response: Response): void {
// be loud about errors
const status = response.status;
const f = status >= 400 ? console.warn : console.info;

const { method, url } = event.request;
const cache = response.headers.get("cache-control") ?? "";
const etag = response.headers.get("etag") ?? "";

const row = [new Date(), method, url, status, event.platform?.context ?? ""];
const row = [
new Date(),
method,
url,
status,
event.route.id,
etag,
cache,
].filter(Boolean);

f(...row);
}

0 comments on commit 4299264

Please sign in to comment.