Skip to content

Rust stderr: eprint! and eprintln!

Use eprint! or eprintln! to print to stderr in Rust. They use the same format-string syntax as print! and println!, but keep diagnostics separate from the program’s primary stdout stream.

EXAMPLE: CI-CHECKEDCOMPILED · examples/format-output/src/output_pages.rs#output-stderr
eprint!("warning: ");
eprintln!("retrying request");

eprintln! writes to standard error and appends a newline. eprint! writes to standard error without adding a newline.

Use eprintln! for ordinary error, warning, or progress lines. Use eprint! only when you intentionally want to keep the line open.

Why stdout and stderr should stay separate

Section titled “Why stdout and stderr should stay separate”

A command-line program may send its real result to stdout so another process can pipe, redirect, or parse it. Progress text mixed into that stream can corrupt the result.

Stderr gives operational messages their own channel:

stdout -> data or primary result
stderr -> errors, warnings, progress, diagnostics

The terminal often shows both streams together, which can hide the distinction during manual testing. Redirection and pipelines reveal why the separation matters.

A caller can redirect stdout to a file while still seeing diagnostics on the terminal, or redirect stderr independently for later inspection.

That is why progress text belongs on stderr when stdout is intended to be machine-consumable data. The terminal may merge the visual presentation, but the operating-system streams remain distinct.

Stderr is a destination, not a logging architecture. These macros do not provide levels, structured fields, filtering, timestamps, or spans.

For a small CLI error message, that simplicity may be exactly right. For durable application diagnostics, use an appropriate logging or tracing layer and decide where that layer writes its output.