mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 01:25:42 -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)->
|
||||
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
|
||||
express.logger.format('prod', productionLogging)
|
||||
app.use(express.logger('prod'))
|
||||
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 })
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue