From d2015f06bedf481efd3692bb5da2a43545682942 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Wed, 2 Jul 2025 18:26:58 +0200 Subject: Consistent request logging --- src/bundle/Server.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/bundle') diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts index c3cfa04a..d7ba9260 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts @@ -16,6 +16,8 @@ along with this program. If not, see . */ +import morgan from "morgan"; + process.on("unhandledRejection", console.error); process.on("uncaughtException", console.error); @@ -59,6 +61,24 @@ async function main() { await Config.init(); await Sentry.init(app); + const logRequests = process.env["LOG_REQUESTS"] != undefined; + if (logRequests) { + app.use( + morgan("combined", { + skip: (req, res) => { + let skip = !( + process.env["LOG_REQUESTS"]?.includes( + res.statusCode.toString(), + ) ?? false + ); + if (process.env["LOG_REQUESTS"]?.charAt(0) == "-") + skip = !skip; + return skip; + }, + }), + ); + } + await new Promise((resolve) => server.listen({ port }, () => resolve(undefined)), ); -- cgit 1.5.1