Skip to content

File appender writes gibberish #1502

Answered by davidbarsky
bubelov asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, the gibberish are ANSI color codes. You'll want to disable colors to Layer writing to a file by passing false to tracing_subscriber::fmt::Layer::with_ansi. Here's an example that should work:

let log_file_appender = tracing_appender::rolling::never(data_dir, "pfd.log");
let (log_file_appender, _log_file_guard) = tracing_appender::non_blocking(log_file_appender);

let subscriber = Registry::default()
    .with(EnvFilter::from_default_env())
    .with(Layer::new().with_writer(std::io::stdout))
    .with(Layer::new().with_ansi(false).with_writer(log_file_appender));

tracing::subscriber::set_global_default(subscriber)?;

tracing_log::LogTracer::builder()
    .with_max_level(tracing_core::L…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@hawkw
Comment options

@bubelov
Comment options

@davidbarsky
Comment options

Answer selected by hawkw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants