Customizing output format
See original GitHub issueRef #573, #565, #553, #456, #453, #402, #578, #526, #525, #488
Right now it’s very clear that debug
takes a subjective stance on its output format. This is unsuitable for a variety of use-cases, especially the disparity between the isatty(2) == 0
and == 1
cases.
Let’s figure out how to solve this.
My initial knee-jerk idea would be to introduce a DEBUG_FORMAT
environment variable. It would accept a string with delimiters similar to date-time or printf formats that indicate different elements of a debug log.
This would also remove the need for a plethora of custom environment variables that have been proposed.
We’d have a default format that would then be the same between interactive/non-interactive TTY sessions (fd 2, as always).
This would look something like
DEBUG_FORMAT="%N %m %D"
Where %N
is the namespace (colored if interactive terminal), %m
is the message and %D
is the time diff - the exact format in the screenshot in the readme.
Of course there would be other delimiters available, and the above doesn’t necessarily need to be the default, but it would solve pretty much any use-case imaginable regarding the output format in a non-subjective manner.
That’s just my personal proposal, but this RFC is after any solution, so if you have a different idea please sound off below.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:41
- Comments:27 (11 by maintainers)
I’m honestly only in this thread because I want
debug
to stop automatically returning seconds and instead always return milliseconds.It’s easy to miss that one call took 1000x longer.
Referring to https://github.com/visionmedia/debug/issues/442#issuecomment-443757866 and #442 in general, asking for a JSON output format:
Definitely not - the end consumer of the application should have full control over the output format. This would result in many different output formats, which would make this library useless to most people.
This would be a breaking change as it’s using namespaces for something they aren’t designed to do.
In reality, you could argue that prefixing
J
to any one flag would run it throughJSON.stringify()
.For example, if
%m
is the message, then%Jm
is the message passed throughJSON.stringify()
.It’s not uncommon to prefix flags for extended functionality, so this wouldn’t be breaking ‘the UNIX way’ either.
You’d then have something like the following, giving you guaranteed valid JSON output.