From 62174c5328fa8d30bb4df35e493d4108544e020e Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Mon, 25 Oct 2021 09:41:12 -0700 Subject: [PATCH] proxyauth: only log failed requests by default --- src/proxyauth.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/proxyauth.js b/src/proxyauth.js index a0f7ffc6e..66046b062 100644 --- a/src/proxyauth.js +++ b/src/proxyauth.js @@ -209,7 +209,24 @@ function initializeAuthwallExpressSync() { const json = middleware.json({ strict: true, limit: QUERY_LIMIT }); // application/json - if (process.env.BOX_ENV !== 'test') app.use(middleware.morgan('proxyauth :method :url :status :response-time ms - :res[content-length]', { immediate: false })); + if (process.env.BOX_ENV !== 'test') { + app.use(middleware.morgan(function (tokens, req, res) { + return [ + 'proxyauth', + tokens.method(req, res), + tokens.url(req, res), + tokens.status(req, res), + res.errorBody ? res.errorBody.status : '', // attached by connect-lastmile. can be missing when router errors like 404 + res.errorBody ? res.errorBody.message : '', // attached by connect-lastmile. can be missing when router errors like 404 + tokens['response-time'](req, res), 'ms', '-', + tokens.res(req, res, 'content-length') + ].join(' '); + }, { + immediate: false, + // only log failed requests by default + skip: function (req, res) { return res.statusCode < 400; } + })); + } const router = new express.Router(); router.del = router.delete; // amend router.del for readability further on