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