Is it possible to have tracing write logs to multiple writers, such as stdout and a file?
There is tracing_subscriber::fmt::SubscriberBuilder::with_writer(), but this only allows for one writer to be set.
Another option would be to allow for multiple subscribers, however this does not seem to work, as far as I have tried:
fn init_tracing() {
let file_appender = tracing_appender::rolling::hourly("./logs", "log");
let (file_writer, _guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::fmt()
.with_writer(file_writer)
.init();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
tracing::trace!("Tracing initialized.");
}
thread 'main' panicked at 'Unable to install global subscriber: SetLoggerError(())'
Is it possible to have
tracingwrite logs to multiple writers, such as stdout and a file?There is
tracing_subscriber::fmt::SubscriberBuilder::with_writer(), but this only allows for one writer to be set.Another option would be to allow for multiple subscribers, however this does not seem to work, as far as I have tried: