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
797 stars 124 forks source link

Space left after level #224

Open steinemann opened 2 years ago

steinemann commented 2 years ago

The default message format will print:

[2021-12-22T08:22:29Z TRACE mymodule] <message>

When disable the target (module), there is an extra space before the ].

[2021-12-22T08:19:55Z INFO ] <message>
                          ^ here

Could this be fixed ?

KonradHoeffner commented 2 years ago

Are you sure that there is only one space between TRACE and mymodule? For me, env_logger 0.0.9 prints "[2021-12-22T08:22:29Z TRACE mymodule] " with two spaces between them, so the fix should be simpler. However when I copy that line from my post in Firefox Developer Edition 104, then the two spaces get reduced to one.

epage commented 1 year ago

Without looking into this further, one question I have is if that is padding as INFO is one letter shorter than TRACE.

VorpalBlade commented 9 months ago

I ran into this today:

    let mut builder = Builder::from_env(Env::default().default_filter_or("warn"));
    builder.format_timestamp(None);
    builder.format_target(false);
    //builder.format(|buf, record| {
    //    writeln!(buf, "[{}] {}", record.level(), record.args())
    //});
    builder.init();

Without the commented out code, I get the extra space too. The custom format would fix it for me, except I miss out on colours. I could probably add them back myself, but I'm not sure how to do so in a cross platform way that also works with redirect to file (non-terminal output) etc.

So my question is: How do I get rid of the space but keep the default auto-colour support for the log level?

epage commented 9 months ago

There are ways to doing styling in a cross-platform way though I want to replace this with anstream so you can just put in ANSI escape code styled text though working through our MSRV policy is the main limitation

VorpalBlade commented 9 months ago

@epage is there a way for me as a user to use anstream today with env_logger (MSRV is not an issue for me), or does it require access to internals making it impossible?

epage commented 9 months ago

You might be able to get it to work by setting it to Target::Pipe but I've not tested it for problems you may run into (locking, pipe bugs, etc)

epage commented 7 months ago

298 will switch us to anstream