Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Option to conditionally log to stderr only above a given level

Aperta
#219 8 commenti 9 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
observability

Direzione di ricerca

Inizia individuando la configurazione Target di env_logger e il percorso di Builder::format() menzionato nell'issue. Verifica come i record vengono attualmente instradati verso stdout o stderr, quindi aggiungi un instradamento condizionale in base al livello di log e verifica che i record di livello inferiore usino stdout, mentre i record al livello configurato o superiore usino stderr.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

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:

image

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())
    }
})
Lingua principale
Rust
Stelle
1.1k
Fork
150
Merge medio
3m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-cli/env_logger

Tutte le issue di rust-cli/env_logger

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.