Skip to content

fix: respect NO_COLOR environment variable in dev format#353

Open
luisangelrod wants to merge 1 commit into
expressjs:masterfrom
luisangelrod:fix/no-color-env-var
Open

fix: respect NO_COLOR environment variable in dev format#353
luisangelrod wants to merge 1 commit into
expressjs:masterfrom
luisangelrod:fix/no-color-env-var

Conversation

@luisangelrod

Copy link
Copy Markdown

Summary

The dev format currently outputs ANSI color escape codes unconditionally. This ignores the widely-adopted NO_COLOR convention, which signals that terminal color output is unwanted (accessibility, log pipelines, CI environments, etc.).

Changes

index.js

  • Check 'NO_COLOR' in process.env before compiling the dev format string
  • When NO_COLOR is set, compile a plain format string (no ANSI codes) cached at key 'plain'
  • No change in behavior when NO_COLOR is absent

test/morgan.js

  • Added with NO_COLOR environment variable describe block with two tests: 2xx and 5xx status codes both produce output free of ANSI escape sequences

Testing

npm test  # 90 passing

Closes #302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

morgan('dev') does not respect NO_COLOR=1 environment variable

1 participant