Skip to content

Conversation

@agionoja
Copy link
Contributor

This adds optional colorized output and human-readable formatters for durations and file sizes.

New features:

  • colors option for colorized output (off by default)
  • formatDuration() - formats ms as "1.20s", "45ms", etc.
  • formatFileSize() - formats bytes as "1.2 kB", "120 B", etc.
  • Updated default format to use %durationPretty and %contentLengthPretty

Colors (when enabled):

  • Status codes: green (2xx), cyan (3xx), yellow (4xx), red (5xx)
  • Durations: green (<100ms), yellow (100-500ms), magenta (500ms-1s), red (>1s)
  • Methods: GET (green), POST (cyan), PUT/PATCH (yellow), DELETE (red), HEAD/OPTIONS (magenta)
  • Content length: cyan (1kB-100kB), yellow (100kB-1MB), red (>1MB)

No breaking changes - colors default to off.

@MichaelDeBoey MichaelDeBoey changed the title Feat(logger-middleware) : Add color support and pretty formatters feat(logger-middleware) : add support for color and pretty formatters Nov 25, 2025
@MichaelDeBoey MichaelDeBoey changed the title feat(logger-middleware) : add support for color and pretty formatters feat(logger-middleware): add support for color and pretty formatters Nov 25, 2025
@mjackson
Copy link
Member

Let's default to using color when we detect we are in a TTY. This is going to be tricky since we don't want to lose the ability to run logger middleware in browser/service worker environment.

Something like this could work:

const useColor = typeof process !== 'undefined' &&
  process.stdout.isTTY &&
  process.env.NO_COLOR == null

function colorize(text: string, color: string) {
  return useColor ? `${color}${text}${reset}` : text
}

@MichaelDeBoey
Copy link
Member

@agionoja Something seems to have gone wrong with rebasing on main

@agionoja agionoja force-pushed the feature/pretty-logging branch from 057383f to c74bce0 Compare November 27, 2025 12:54
@agionoja agionoja force-pushed the feature/pretty-logging branch from c74bce0 to dbf0950 Compare November 27, 2025 14:36
@agionoja
Copy link
Contributor Author

@agionoja Something seems to have gone wrong with rebasing on main

Sorry about that. I've fixed it.

@agionoja
Copy link
Contributor Author

Let's default to using color when we detect we are in a TTY. This is going to be tricky since we don't want to lose the ability to run logger middleware in browser/service worker environment.

Something like this could work:

const useColor = typeof process !== 'undefined' &&
  process.stdout.isTTY &&
  process.env.NO_COLOR == null

function colorize(text: string, color: string) {
  return useColor ? `${color}${text}${reset}` : text
}

I've done as you suggested. Now we only use colors in supported envs and if the user explicitly uses the colors option.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants