From 66872d136d9a460ca6f938e8511cee0fc97f2a4e Mon Sep 17 00:00:00 2001 From: mishless Date: Fri, 23 May 2014 13:58:52 +0300 Subject: [PATCH] Update connect-logger.js to work correctly with express When used with express levels are wrong since send() does not call writeHead, but sets responseCode on response. --- lib/connect-logger.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/connect-logger.js b/lib/connect-logger.js index 8c9e768..cf9c60f 100644 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -84,6 +84,12 @@ function getLogger(logger4js, options) { res.end = end; res.end(chunk, encoding); res.responseTime = new Date() - start; + //status code response level handling + if(res.statusCode && options.level === 'auto'){ + level = levels.INFO; + if(res.statusCode >= 300) level = levels.WARN; + if(res.statusCode >= 400) level = levels.ERROR; + } if (thislogger.isLevelEnabled(level)) { if (typeof fmt === 'function') { var line = fmt(req, res, function(str){ return format(str, req, res); });