Skip to content

Writing warn! and info! to different files #1750

Answered by hawkw
jafioti asked this question in Q&A
Discussion options

You must be logged in to vote

Sending different kinds of events to different outputs can be accomplished with MakeWriter filtering. You can create a pair of rolling file appenders and combine them using the MakeWriterExt combinators.

In your case, to write warn and info messages to different rolling appenders, it might look something like this:

    use tracing_subscriber::fmt::writer::MakeWriterExt;

    let info_appender = tracing_appender::rolling::minutely("./logs/info", "prefix.log");
    let (info_appender, _info_guard) = tracing_appender::non_blocking(info_appender);
    let warn_appender = tracing_appender::rolling::minutely("./logs/info", "prefix.log");
    let (warn_appender, _warn_guard) = tracing_appender::n…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jafioti
Comment options

@hawkw
Comment options

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