Skip to content
Open
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
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) {
? res.statusCode
: undefined

// check for NO_COLOR environment variable (https://no-color.org)
var noColor = process.env.NO_COLOR != null

// get status color
var color = status >= 500 ? 31 // red
: status >= 400 ? 33 // yellow
Expand All @@ -220,12 +223,15 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) {
: 0 // no color

// get colored function
var fn = developmentFormatLine[color]
var fn = developmentFormatLine[color + (noColor ? '-nc' : '')]

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')
fn = developmentFormatLine[color + (noColor ? '-nc' : '')] = compile(
noColor
? ':method :url :status :response-time ms - :res[content-length]'
: '\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