From add5d998c041ca3c0c4d7258c170dc3f63088b87 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Sun, 15 Aug 2021 20:50:18 +0200 Subject: [PATCH] feat(logging): Exclude /status route from logging This patch should reduce the logging noise a lot, by removing the `/status` route from logging unless hedgedoc is running in debug mode or the route throws an error code. This is achieved by providing a "skip"-function to the morgan logging provider. Signed-off-by: Sheogorath --- app.js | 6 ++++++ lib/web/statusRouter.js | 1 + 2 files changed, 7 insertions(+) diff --git a/app.js b/app.js index beb0743b9..d36242e1c 100644 --- a/app.js +++ b/app.js @@ -65,6 +65,12 @@ if (!config.useSSL && config.protocolUseSSL) { // logger app.use(morgan('combined', { + skip: function(req, res) { + // skip logging if specified + // unless the app is running in debug mode + // or throws an error + return req.skipLogging && config.loglevel !== "debug" && res.statusCode < 400 + }, stream: logger.stream })) diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index d939a3fee..c26eb7c03 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -14,6 +14,7 @@ const statusRouter = module.exports = Router() // get status statusRouter.get('/status', function (req, res, next) { + req.skipLogging = true realtime.getStatus(function (data) { res.set({ 'Cache-Control': 'private', // only cache by client