Skip to content

Multiple Writers or Subscribers #971

@mankinskin

Description

@mankinskin

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(())'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions