Tweaked status colors for production logging; applying it only when in production.

This commit is contained in:
Nick Winter 2014-03-03 08:10:36 -08:00
parent ab16c0f8e0
commit a5adf5a1bf

View file

@ -21,14 +21,23 @@ setupRequestTimeoutMiddleware = (app) ->
productionLogging = (tokens, req, res)->
status = res.statusCode
color = 31
if(status != 200 && status != 304)
return '\x1b[90m' + req.method+ ' ' + req.originalUrl + ' '+ '\x1b[' + color + 'm' + res.statusCode+ ' \x1b[90m'+ (new Date - req._startTime)+ 'ms' + '\x1b[0m';
color = 32
if status >= 500 then color = 31
else if status >= 400 then color = 33
else if status >= 300 then color = 36
elapsed = (new Date()) - req._startTime
elapsedColor = if elapsed < 500 then 90 else 31
if (status isnt 200 and status isnt 304) or elapsed > 500
return "\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m"
null
setupExpressMiddleware = (app) ->
setupRequestTimeoutMiddleware app
if config.isProduction
express.logger.format('prod', productionLogging)
app.use(express.logger('prod'))
else
app.use(express.logger('dev'))
app.use(express.static(path.join(__dirname, 'public')))
app.use(useragent.express())
@ -105,6 +114,3 @@ exports.setExpressConfigurationOptions = (app) ->
app.set('views', __dirname + '/app/views')
app.set('view engine', 'jade')
app.set('view options', { layout: false })