Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) {
? res.statusCode
: undefined

// check if color is disabled
var noColor = process.env.NO_COLOR != null && process.env.NO_COLOR !== ''

// get status color
var color = status >= 500 ? 31 // red
var color = noColor ? 'no-color'
: status >= 500 ? 31 // red
: status >= 400 ? 33 // yellow
: status >= 300 ? 36 // cyan
: status >= 200 ? 32 // green
Expand All @@ -224,8 +228,12 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) {

if (!fn) {
// compile
fn = developmentFormatLine[color] = compile('\x1b[0m:method :url \x1b[' +
color + 'm:status\x1b[0m :response-time ms - :res[content-length]\x1b[0m')
if (noColor) {
fn = developmentFormatLine[color] = compile(':method :url :status :response-time ms - :res[content-length]')
} else {
fn = developmentFormatLine[color] = compile('\x1b[0m:method :url \x1b[' +
color + 'm:status\x1b[0m :response-time ms - :res[content-length]\x1b[0m')
}
}

return fn(tokens, req, res)
Expand Down
Loading