env_logger icon indicating copy to clipboard operation
env_logger copied to clipboard

Space left after level

Open steinemann opened this issue 3 years ago • 7 comments

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 ?

steinemann avatar Dec 22 '21 08:12 steinemann

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.

KonradHoeffner avatar Aug 08 '22 10:08 KonradHoeffner

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

epage avatar Nov 10 '22 03:11 epage

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?

VorpalBlade avatar Nov 04 '23 17:11 VorpalBlade

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

epage avatar Nov 06 '23 15:11 epage

@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?

VorpalBlade avatar Nov 06 '23 17:11 VorpalBlade

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 avatar Nov 06 '23 17:11 epage

#298 will switch us to anstream

epage avatar Jan 18 '24 19:01 epage