This version of the documentation is outdated, and features documented here may work differently now. You can see the latest stable version of the docs here.

Debugging

If you're used to Rust, you might be expecting to be able to call println! or dbg! to easily print a value to the browser console while working on an app, however this is unfortunately not yet the case (this is an issue in the lower-level libraries that Perseus depends on).

However, Perseus exports a macro called web_log! that can be used to print to the console. It accepts syntax identical to format!, println!, and the like and behaves in the same way, but it will print to the browser console instead of the terminal. Because Perseus builds your templates on the server as well as in the browser though, some of the calls to this macro may run both on a 'normal' architecture and in Wasm. web_log! is designed for this, and will print to stdout (as println! does) if it's used on the server-side (though you'll need to run something like perseus snoop build to see the output).

Debugging the build process

If you have a problem in your build process, you'll probably notice quite quickly that you can't see any dbg!, println!, or web_log! calls in your terminal when you run perseus serve (or export, build, etc.). This is because the CLI hides the output of the commands that it runs behind the scenes (if you've ever had the CLI spout an error at you and show you everything it's done behind the scenes, you'll probably understand why!). As useful as this is for simple usability, it can be extremely annoying for logging, so the CLI provides a separate command perseus snoop <process>, which allows you to run one of the commands that the CLI does, directly. Usually, this will be perseus snoop build, though you can also use perseus snoop wasm-build if you're having an issue in your Wasm building (usually caused by a crate that can't work in the browser), or perseus snoop serve if you're getting errors on the server (which shouldn't happen unless you've modified it). To learn more, see this page.