Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Priority issues between environment variable `RUST_LOG` and function call `filter_level` / `filter`.

Đang mở
#259 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
observability-sre

Hướng nghiên cứu

Bắt đầu từ hành vi của logger builder liên quan đến filter_level(level), filter(None, level) và việc khởi tạo RUST_LOG. Xác định cách các mức ưu tiên của chúng hiện đang được áp dụng, sau đó xác định thứ tự ưu tiên cần có để RUST_LOG có thể ghi đè level được hardcode và bổ sung coverage cho cả hai dạng khởi tạo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Environment variable RUST_LOG can only used to set "default policy", which means if filter_level(level) or filter(None, level) (they are practically equivalent) called at logger init, then environment variable RUST_LOG will cannot override the hardcoded log level.

This because environment variable RUST_LOG will initialized first (by default), then override by program logic. This might be a bug because commonly priority of environment variable > cli flag > config file or hardcoded.

Demo:

use log::{info, LevelFilter};

fn main() {
    // Hardcoded log level by using `filter_level` or `filter`.
    env_logger::builder().filter_level(LevelFilter::Info).init();

    info!("starting up");
}

If set the environment variable RUST_LOG=warn, info output will still print:

demo on  master [?] is 📦 v0.1.0 via 🦀 v1.67.0
at 14:04:38 fsh ❯ RUST_LOG=warn cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/demo`
[2023-01-31T06:04:43Z INFO  demo] starting up

But if not setting log level at logger init:

use log::info;

fn main() {
    env_logger::builder().init();
    info!("starting up");
}

Then log level can be controlled easylly from RUST_LOG:

demo on  master [?] is 📦 v0.1.0 via 🦀 v1.67.0
at 14:07:17 fsh ❯ RUST_LOG=info cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/demo`
[2023-01-31T06:07:21Z INFO  demo] starting up

demo on  master [?] is 📦 v0.1.0 via 🦀 v1.67.0
at 14:07:21 fsh ❯ RUST_LOG=warn cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/demo`

Ngôn ngữ chính
Rust
Star
1.1k
Fork
150
Merge trung bình
3 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-cli/env_logger

Tất cả issue của rust-cli/env_logger

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.