diff --git a/lib/api/middlewares/error-middleware.js b/lib/api/middlewares/error-middleware.js index 0822c144..583b54f5 100644 --- a/lib/api/middlewares/error-middleware.js +++ b/lib/api/middlewares/error-middleware.js @@ -9,6 +9,7 @@ module.exports = function errorMiddleware (/* options */) { allErrors = populateLimitErrors(allErrors); + // TODO REMOVE THIS THREE LINES PLEASE const label = err.label || 'UNKNOWN'; err = allErrors[0] || new Error(label); allErrors[0] = err; @@ -20,8 +21,8 @@ module.exports = function errorMiddleware (/* options */) { statusCode = 200; } - allErrors.forEach((err) => debug('[%s ERROR] -- %d: %s, %s', label, statusCode, err, err.stack)); - allErrors.forEach((err) => logger.error(err)); + allErrors.forEach((err) => debug('[%s ERROR] -- %d: %s, %s', err.label || 'UNKNOWN', statusCode, err, err.stack)); + logger.error({ errors: allErrors }); var errorResponseBody = { errors: allErrors.map(errorMessage), diff --git a/lib/api/middlewares/logger.js b/lib/api/middlewares/logger.js index 93a02a03..09b92ef0 100644 --- a/lib/api/middlewares/logger.js +++ b/lib/api/middlewares/logger.js @@ -7,8 +7,8 @@ module.exports = function initLogger ({ logger }) { const id = req.get('X-Request-Id') || uuid.v4(); res.locals.logger = logger.child({ id }); - res.locals.logger.info(req); - res.on('finish', () => res.locals.logger.info(res)); + res.locals.logger.info({ request: req }); + res.on('finish', () => res.locals.logger.info({ response: res })); next(); }; diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 33646049..d9c9b85c 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -8,7 +8,12 @@ module.exports = class Logger { const logLevelFromNodeEnv = NODE_ENV === 'test' ? 'fatal' : 'info'; const options = { base: null, // Do not bind hostname, pid and friends by default - level: LOG_LEVEL || logLevelFromNodeEnv + level: LOG_LEVEL || logLevelFromNodeEnv, + serializers: { + request: pino.stdSerializers.req, + response: pino.stdSerializers.res, + errors: (errors) => errors.map((err) => pino.stdSerializers.err(err)) + } }; const dest = pino.destination({ sync: false }); // stdout