Logging to stderr
joshwlewis opened this issue · 2 comments
Unlike cli.action
, the basic logging commands like cli.log
, cli.info
, cli.debug
, cli.url
only send text to stdout
. There is no option to send these messages to stderr
. Using stdout
for these messages makes these utilities unusable for CLIs aiming to use stdout/stdin pipes.
For instance, when creating a pipeable command like oclif create-my-config | xargs cat
, the only message that should go to stdout would be the filename. Any other informational or human messaging (such as 'Using default config') is better suited for stderr
to prevent pipe corruption.
It would be nice to have an option to send informational messages to stderr
instead. It might even make more sense to make stderr
the default, and let stdout
be a more intentional and explicit choice. Given that many CLIs around the unix ecosystem operate in this manner, we'd be in good company.
make stderr the default
While this might be a breaking change for folks that have been forced to parse stdout for results of a command, it would ensure that stdout is clean, so that intentional command output is not mixed up with logs.
Accepting a writable stream as input would be even better. That would allow folks to use not only process.stderr
but also a stream of their own creation, which is much easier to observe in an automated testing environment.