Plumber: Plumber messages are sent to stderr instead of stdout

Created on 30 Sep 2019  路  3Comments  路  Source: rstudio/plumber

Steps to reproduce:

  • Configure stdout and stderr to output to different places.
  • Launch plumber through Rscript with a file like this:
library(plumber)
r <- plumb("some_file.R")
r$run(host = host, port = port)
  • Check the standard output and standard error that is produced.

Expected behavior: information messages such as

Starting server to listen on port 1234

should go into standard output.

Actual behavior: information messages go into standard error instead.

will not fix

Most helpful comment

It's also possible to catch message() signals at the application level and write them to standard output, if that's what you absolutely need:

withCallingHandlers(
  message("Informational message."),
  message = function(m) {
    cat(m$message)
    invokeRestart("muffleMessage")
  }
)

This can also be used to e.g. catch library messages and reformat them for structured logging output, something that becomes impossible when using cat() directly as proposed.

All 3 comments

Good catch!

I believe message produces stderr output. We should probably change them to cat statements where appropriate.

It's also possible to catch message() signals at the application level and write them to standard output, if that's what you absolutely need:

withCallingHandlers(
  message("Informational message."),
  message = function(m) {
    cat(m$message)
    invokeRestart("muffleMessage")
  }
)

This can also be used to e.g. catch library messages and reformat them for structured logging output, something that becomes impossible when using cat() directly as proposed.

Was this page helpful?
0 / 5 - 0 ratings