borntyping / rust-simple_logger

A rust logger that prints all messages with a readable output format.
https://crates.io/crates/simple_logger
MIT License
220 stars 48 forks source link

no colors when using feature stderr and redirecting stdout #71

Closed andbleo closed 11 months ago

andbleo commented 1 year ago

When I have the stderr and colors features enabled and redirect just stdout, the colors in my stderr logs are no longer there. If I remove the stderr feature and try redirecting stderr, my stdout logs do have color. Is this expected behavior?

This is on macOS and happens in both iTerm2 and the vs code terminal.

Here is how I pull in simple_logger in Cargo.toml: simple_logger = { version = "4.0.0", features = ["stderr"] }

borntyping commented 1 year ago

I don't think this is expected. I can't see any reason this would happen - the colors and stderr features are pretty separate. Do you get coloured logs if you enable colors and stderr without redirecting any output?

I can see a potential bug in the code where this might happen on Windows specifically: https://github.com/borntyping/rust-simple_logger/blob/main/src/lib.rs#L463

andbleo commented 1 year ago

I do get colors when I don't redirect stdout. Perhaps it is a bug in the colored dependency for non-windows platforms?

borntyping commented 1 year ago

Ah: this does look like it may be a bug in colored, which checks STDOUT to decide if it should show colours.

https://docs.rs/colored/latest/src/colored/control.rs.html#108

andbleo commented 1 year ago

I will open an issue with colored and link to this one.

borntyping commented 11 months ago

Closing this as it looks like it's currently intended behavior on coloured's part.