Search code examples
rustrust-rocket

How do I use print! with Rocket when compiling for release?


I've got some route handlers with print!() statements in it. They work just fine when I compile my app for debug. However, when compiling for release, Rocket appears to be "muting" all the print statements (as well as logging functions from log crate). Why is it doing so? How do I force it to print things then building for release? I suspect it might be connected to log level, which is automatically set to critical when compiling for release, however, I'm not quite sure what level do print! statements have and how to change the logging level.


Solution

  • You are specifically mentioning print!(), which does not flush() stdout after writing to it, so its output usually appears to be muted.

    As you mention, rocket sets the default log-level to normal in debug builds, which will produce more/any logs, which in turn cause a flush() and therefore your print!()-output to be flushed as well.

    Use println!() or manually flush() .