# Rust stderr: eprint! and eprintln!

> Print Rust errors, warnings, and progress messages to stderr with eprint! and eprintln!, keeping machine-readable stdout output clean.

HTML: https://rustprint.com/output/stderr-eprint-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.

**Writing a warning to standard error**

```rust
eprint!("warning: ");
eprintln!("retrying request");
```

## Print to stderr in Rust

`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

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:

```text
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.

## Redirection keeps the streams useful

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.

## Not a logging system

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.

## Sources

- [eprint!](https://doc.rust-lang.org/std/macro.eprint.html)
- [eprintln!](https://doc.rust-lang.org/std/macro.eprintln.html)

## Related RustPrint guides

- [Rust print without newline: print! vs println!](/output/print-and-println/index.md): Print in Rust with or without a newline. Compare print! and println!, flush stdout for prompts, and avoid repeated stdout locking.
- [Rust output macros: print!, eprintln!, write!, and format!](/output/output-macros/index.md): Choose the right Rust output macro for stdout, stderr, an owned String, or an existing writer, including newline, flushing, and buffering behavior.
- [Rust dbg! macro: inspect values with Debug](/debug/inspect-values/index.md): Use Rust dbg! to print expressions to stderr, understand its return and move behavior, and compare compact {:?} with pretty {:#?} Debug output.
