-
I am using the rolling appender to write to files, but I would like to write warn and info messages to different paths, from two different rolling appenders. Here's what I'm doing now:
I tried to set a second appender as global, but you can only have one global writer at a time. Is there a way to split the output of info! to "/log/info" and warn to "/log/warn" ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Sending different kinds of events to different outputs can be accomplished with 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::non_blocking(warn_appender);
let files = info_appender
.with_min_level(Level::INFO)
.or_else(warn_appender.with_max_level(Level::WARN));
tracing_subscriber::fmt()
.with_writer(files)
.with_ansi(false)
.with_max_level(Level::WARN)
.init(); Also, note that the |
Beta Was this translation helpful? Give feedback.
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 theMakeWriterExt
combinators.In your case, to write warn and info messages to different rolling appenders, it might look something like this: