rust-cli / rust-cli/env_logger
Option to conditionally log to stderr only above a given level
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 149
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
When using env_logger in a binary running in Google Kubernetes Engine, everything it logs gets recorded as an error log because it logs to stderr by default:

This is just the actix-web logger middleware logging requests from the Gcloud healthcheck service at INFO (plus an easter egg of a web crawler looking for an admin login form?), but Gcloud thinks they're error logs because they were printed to stderr.
Of course, we could just set Target::Stdout and call it a day, but I would like to retain the ability to print actual error logs to stderr as we want to set this up to page someone if our API service is throwing actual errors.
I'm thinking another variant to Target that looks something like:
enum Target {
// ...
// Print to `stderr` if the record level is at or above the given `log::Level`, otherwise `stdout`.
StdoutOrStderrAt(log::Level),
}
I'm also considering, as a workaround, using the Builder::format() method to conditionally print to stderr but I'm not sure if this would break things. It's suboptimal either way:
builder.format(|f, record| {
if record.level() >= log::Level::Error {
eprintln!(/* format `record` using the same format as the default formatter */)
} else {
write!(fmt, "{}", record.args())
}
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating env_logger's Target configuration and the Builder::format() path mentioned in the issue. Check how records are currently routed to stdout or stderr, then add conditional routing by log level and verify that lower-level records use stdout while records at or above the configured level use stderr.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100