Update server development logging

Provide more details.
This commit is contained in:
Matt Lott 2014-10-26 10:52:22 -07:00
parent 7c21d5921e
commit 6d9e243968

View file

@ -27,6 +27,16 @@ productionLogging = (tokens, req, res) ->
return "\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m" return "\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m"
null null
developmentLogging = (tokens, req, res) ->
status = res.statusCode
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
"\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m"
setupExpressMiddleware = (app) -> setupExpressMiddleware = (app) ->
if config.isProduction if config.isProduction
express.logger.format('prod', productionLogging) express.logger.format('prod', productionLogging)
@ -35,6 +45,7 @@ setupExpressMiddleware = (app) ->
return false if req.headers.host is 'codecombat.com' # CloudFlare will gzip it for us on codecombat.com # But now it's disabled. return false if req.headers.host is 'codecombat.com' # CloudFlare will gzip it for us on codecombat.com # But now it's disabled.
compressible res.getHeader('Content-Type') compressible res.getHeader('Content-Type')
else else
express.logger.format('dev', developmentLogging)
app.use(express.logger('dev')) app.use(express.logger('dev'))
app.use(express.static(path.join(__dirname, 'public'))) app.use(express.static(path.join(__dirname, 'public')))
app.use(useragent.express()) app.use(useragent.express())