Skip to content

feat(cli): support configuration via PINO_PRETTY_* environment variables#651

Closed
mahmoodhamdi wants to merge 1 commit intopinojs:masterfrom
mahmoodhamdi:feat/env-var-config
Closed

feat(cli): support configuration via PINO_PRETTY_* environment variables#651
mahmoodhamdi wants to merge 1 commit intopinojs:masterfrom
mahmoodhamdi:feat/env-var-config

Conversation

@mahmoodhamdi
Copy link
Copy Markdown

Summary

Closes #554.

Adds environment variable support to the pino-pretty CLI. All options are configurable with a PINO_PRETTY_ prefix and SCREAMING_SNAKE_CASE naming.

Priority: CLI flags > config file > env vars (env vars are lowest priority, acting as a global fallback).

Env var → CLI flag mapping

Environment Variable CLI Flag
PINO_PRETTY_COLORIZE --colorize
PINO_PRETTY_CRLF --crlf
PINO_PRETTY_ERROR_PROPS --errorProps
PINO_PRETTY_LEVEL_FIRST --levelFirst
PINO_PRETTY_MINIMUM_LEVEL --minimumLevel
PINO_PRETTY_CUSTOM_LEVELS --customLevels
PINO_PRETTY_CUSTOM_COLORS --customColors
PINO_PRETTY_USE_ONLY_CUSTOM_PROPS --useOnlyCustomProps
PINO_PRETTY_ERROR_LIKE_OBJECT_KEYS --errorLikeObjectKeys
PINO_PRETTY_MESSAGE_KEY --messageKey
PINO_PRETTY_LEVEL_KEY --levelKey
PINO_PRETTY_LEVEL_LABEL --levelLabel
PINO_PRETTY_MESSAGE_FORMAT --messageFormat
PINO_PRETTY_TIMESTAMP_KEY --timestampKey
PINO_PRETTY_TRANSLATE_TIME --translateTime
PINO_PRETTY_IGNORE --ignore
PINO_PRETTY_INCLUDE --include
PINO_PRETTY_HIDE_OBJECT --hideObject
PINO_PRETTY_SINGLE_LINE --singleLine

Boolean options accept true/1 and false/0 (case-insensitive). Invalid values are silently ignored.

Usage example

# Instead of:
myapp | pino-pretty --singleLine --levelFirst

# You can now use:
PINO_PRETTY_SINGLE_LINE=true PINO_PRETTY_LEVEL_FIRST=true myapp | pino-pretty

# Or in a .env / Docker environment:
PINO_PRETTY_IGNORE=pid,hostname
PINO_PRETTY_TRANSLATE_TIME=SYS:yyyy-mm-dd HH:MM:ss

Test plan

  • 7 new tests in test/cli-env.test.js covering boolean options (true/1), string options, CLI-over-env priority, and invalid boolean value handling
  • All 357 existing tests continue to pass (npm test)

All CLI options are now configurable through environment variables using the
PINO_PRETTY_ prefix and SCREAMING_SNAKE_CASE naming. Priority is maintained
as: CLI flags > config file > env vars.

Example mappings:
  --levelFirst    → PINO_PRETTY_LEVEL_FIRST=true
  --singleLine    → PINO_PRETTY_SINGLE_LINE=true
  --ignore        → PINO_PRETTY_IGNORE=pid,hostname
  --translateTime → PINO_PRETTY_TRANSLATE_TIME=SYS:yyyy-mm-dd HH:MM:ss

Boolean options accept true/1 and false/0 (case-insensitive). Invalid boolean
values are silently ignored. String options are passed through as-is.

Closes pinojs#554
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jsumners jsumners closed this Mar 23, 2026
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.

Use environment variables for configuration

3 participants