tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.53k stars 725 forks source link

Update fmt-multiple-writers.rs example #3139

Open kadenlnelson opened 1 week ago

kadenlnelson commented 1 week ago

Motivation

Related https://github.com/tokio-rs/tracing/issues/3116

A common use-case is to write colored (ANSI) logs to stdout and write non-colored logs to a file. Where that file may be forwarded to an aggregator, or viewed in an editor, which expects the contents to not have color formatting.

Solution

This PR updates the fmt-multiple-writers.rs example to demonstrate this use-case.

One additional change that's not related to what's described above is the printing of the log file contents to stdout after the example has finished shaving Yaks. The motive being that the log file TempDir is dropped after the example has finished. Currently, the end-user doesn't have a way to inspect the contents of the file without hopping into a debugger, modifying the example, or writing the file to a path that persists after execution.

Example Output

Screenshot 2024-11-17 at 11 42 33 PM