jordansissel / fpm

Effing package management! Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity.
http://fpm.readthedocs.io/en/latest/
Other
11.13k stars 1.07k forks source link

Error messages should be redirected to stderr, not stdout. #1383

Open Salamandar opened 7 years ago

Salamandar commented 7 years ago

I was trying to call FPM while redirecting stdout to out.log and stderr to err.log

Errors should be redirected to stderr, warnings are okay in stderr too.

AnthonyMastrean commented 6 years ago

I went digging around for the FPM-specific error messages, for example

Fix the above problems, and you'll be rolling package in no time!

You can find it in fpm/command and you'll see that it's just calling logger.fatal(). That appears to be the built-in Logger. The docs indicate that an instance can write exclusively to a file or STDOUT/STDERR.

I think you'd need a much broader change to "fix" logging. Something like...

I think maybe this comment provides some info on the author's opinion on logging 😅

      # Log both stdout and stderr as 'info' because nobody uses stderr for
      # actually reporting errors and as a result 'stderr' is a misnomer.

I can't actually find any Logger.new calls, so maybe I'm not figuring out the whole situation 🤷‍♂️

AnthonyMastrean commented 6 years ago

Oh, I see... the author is using another one of his gems, Cabin, to provide some specialized logging.

jordansissel commented 6 years ago

Indeed. The logs of fpm is not necessarily intended to be passed to other programs for additional processing, so in this respect the concept of "stdout" (to be piped to another program) and "stderr" (for human consumption) separately doesn't have much difference because there is only one stream of text reporting coming from fpm and that is from the logger. Any other output is writing files to disk (such as the package to be created).

Given this, it's hard for me to understand the value of having two different streams "non errors" and "errors" being routed to two different file descriptors.

Regarding the report, that some things show up in err.log for the given example, these are not warnings I can control as they are triggered by dependencies as they interact with the Ruby interpreter and are written by Ruby to stderr and not by fpm.

AnthonyMastrean commented 6 years ago

@jordansissel However, fpm is a command-line utility and is probably expected to behave as such, especially if it's run as part of a CI or other kind of automated pipeline. I would expect two major behaviors (besides, obviously, producing packages)

The definition of "proper", in these contexts, is hardly settled in all of the industry, though!

It looks like fpm is consistent in it's own logging to the file and, finally, STDOUT. I think there might be two actions here...

deragon commented 4 years ago

@jordansissel, I just hit this problem because in my build script, I parse STDOUT to fetch the name of the created package, ignoring any other line, including errors. Thus when an error occurs, I do not see the error on the console. If the error was sent to STDERR, it would show up. That is the standard Unix way of doing things. logger.error() and logger.fatal() should be redirected to STDERR.