Steps to reproduce:
stdout and stderr to output to different places.Rscript with a file like this:library(plumber)
r <- plumb("some_file.R")
r$run(host = host, port = port)
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.
Good catch!
I believe message produces stderr output. We should probably change them to cat statements where appropriate.
Prior art: shiny emits a "Listening on ..." message.
https://github.com/rstudio/shiny/blob/29d24d7e08f161d79c8f227723fbec67353b6fc9/R/server.R#L590
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.
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: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.