mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Tweaked status colors for production logging; applying it only when in production.
This commit is contained in:
parent
ab16c0f8e0
commit
a5adf5a1bf
1 changed files with 14 additions and 8 deletions
|
@ -21,14 +21,23 @@ setupRequestTimeoutMiddleware = (app) ->
|
||||||
|
|
||||||
productionLogging = (tokens, req, res)->
|
productionLogging = (tokens, req, res)->
|
||||||
status = res.statusCode
|
status = res.statusCode
|
||||||
color = 31
|
color = 32
|
||||||
if(status != 200 && status != 304)
|
if status >= 500 then color = 31
|
||||||
return '\x1b[90m' + req.method+ ' ' + req.originalUrl + ' '+ '\x1b[' + color + 'm' + res.statusCode+ ' \x1b[90m'+ (new Date - req._startTime)+ 'ms' + '\x1b[0m';
|
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) ->
|
setupExpressMiddleware = (app) ->
|
||||||
setupRequestTimeoutMiddleware app
|
setupRequestTimeoutMiddleware app
|
||||||
express.logger.format('prod', productionLogging)
|
if config.isProduction
|
||||||
app.use(express.logger('prod'))
|
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(express.static(path.join(__dirname, 'public')))
|
||||||
app.use(useragent.express())
|
app.use(useragent.express())
|
||||||
|
|
||||||
|
@ -105,6 +114,3 @@ exports.setExpressConfigurationOptions = (app) ->
|
||||||
app.set('views', __dirname + '/app/views')
|
app.set('views', __dirname + '/app/views')
|
||||||
app.set('view engine', 'jade')
|
app.set('view engine', 'jade')
|
||||||
app.set('view options', { layout: false })
|
app.set('view options', { layout: false })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue