Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid text coloring when using tracing-appender?

When I write logs to a file with tracing-appender, I get output with terminal color artifacts which do not render when viewing them as a text file:

[2mOct 02 23:44:57.484[0m [34mDEBUG[0m

Is there a way to drop these artifacts?

like image 783
Viktor Kulikov Avatar asked Apr 15 '26 23:04

Viktor Kulikov


1 Answers

The with_ansi() option is on by default when using tracing_subcriber::fmt(). Set it to false by using the builder method to declare your subscriber:

let (non_blocking, _guard) = tracing_appender::non_blocking(TestWriter);

tracing_subscriber::fmt()
    .with_writer(non_blocking)
    .with_ansi(false) // <------ this
    .init();

You can have multiple subscribers if you want to inject color on the terminal but not in the file.

like image 176
Ahmed Masud Avatar answered Apr 19 '26 01:04

Ahmed Masud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!