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.
This commit is contained in:
mishless
2014-05-23 13:58:52 +03:00
committed by Vladimir Mitev
parent 49849a545a
commit 66872d136d

View File

@@ -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); });