rust-cli / env_logger

A logging implementation for `log` which is configured via an environment variable.
https://docs.rs/env_logger
Apache License 2.0
782 stars 124 forks source link

env_logger doesn't output anything #311

Closed IvanovOleg closed 5 months ago

IvanovOleg commented 5 months ago

Hello, I have a simple app that should log one string, but it doesn't: Cargo.toml:

[package]
name = "playground"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
env_logger = "0.11"

main.rs:

use log::info;
fn main() {
    env_logger::init();
    info!("program started");
    println!("Hello world!");
}

Result:

PS C:\Users\oliva\Documents\playground> cargo run
   Compiling playground v0.1.0 (C:\Users\oliva\Documents\playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.48s
     Running `target\debug\playground.exe`
Hello world!

Tried using https://play.rust-lang.org/ as well, no output!

epage commented 5 months ago

To make it easier to copy/paste, I made

#!/usr/bin/env nargo
---
[dependencies]
log = "0.4"
env_logger = "0.11"
---

use log::info;
fn main() {
    env_logger::init();
    info!("program started");
    println!("Hello world!");
}
$ ./run.rs
Hello World!
$ RUST_LOG=trace ./run.rs
[2024-02-16T17:04:41Z INFO  env_logger_311] program started
Hello world!

By default env_logger reports nothing back. You can use filter_level to set the level you want shown. clap-verbosity-flag helps provide a CLI for this.

As this is working as expected, I'm going to go ahead and close this. If there is a reason we should re-evaluate, let us know!

IvanovOleg commented 5 months ago
PS C:\Users\oliva\Documents\playground> Set-Variable -Name "RUST_LOG" -Value "trace"
PS C:\Users\oliva\Documents\playground> echo $RUST_LOG
trace
PS C:\Users\oliva\Documents\playground> cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target\debug\playground.exe`
Hello world!
PS C:\Users\oliva\Documents\playground>
epage commented 5 months ago

I have no powershell experience so I can't answer to what is going wrong between powershell and env_logger.

IvanovOleg commented 5 months ago
PS C:\Users\oliva\Documents\playground> $Env:RUST_LOG = 'trace'
PS C:\Users\oliva\Documents\playground> $Env:RUST_LOG
trace
PS C:\Users\oliva\Documents\playground> cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target\debug\playground.exe`
[2024-02-16T17:28:54Z INFO  playground] program started
Hello world!