-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(logger-middleware): add support for color and pretty formatters #10862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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
} |
|
@agionoja Something seems to have gone wrong with rebasing on |
057383f to
c74bce0
Compare
c74bce0 to
dbf0950
Compare
Sorry about that. I've fixed it. |
I've done as you suggested. Now we only use colors in supported envs and if the user explicitly uses the colors option. |
Also, introduce "action" naming to describe an individual route handler.
This adds optional colorized output and human-readable formatters for durations and file sizes.
New features:
colorsoption for colorized output (off by default)formatDuration()- formats ms as "1.20s", "45ms", etc.formatFileSize()- formats bytes as "1.2 kB", "120 B", etc.%durationPrettyand%contentLengthPrettyColors (when enabled):
No breaking changes - colors default to off.