Merge pull request #224 from idalv/express_fix

Update connect-logger.js to work correctly with express
This commit is contained in:
Gareth Jones 2014-08-02 03:30:05 +10:00
commit b71f635267

View File

@ -84,6 +84,12 @@ function getLogger(logger4js, options) {
res.end = end; res.end = end;
res.end(chunk, encoding); res.end(chunk, encoding);
res.responseTime = new Date() - start; 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 (thislogger.isLevelEnabled(level)) {
if (typeof fmt === 'function') { if (typeof fmt === 'function') {
var line = fmt(req, res, function(str){ return format(str, req, res); }); var line = fmt(req, res, function(str){ return format(str, req, res); });