Skip to content

Simultaneous logging #2299

Answered by davidbarsky
TornaxO7 asked this question in Q&A
Sep 8, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Yes, take a look at this example. To adopt it to your use-case, replace the fmt::Layer() on line 18 with tracing_journald::Layer::Layer. The code will look something like this:

use std::io;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter};

fn main() {
    let file_appender = tracing_appender::rolling::hourly(dir, "example.log");
    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

    let subscriber = tracing_subscriber::registry()
        .with(EnvFilter::from_default_env().add_directive(tracing::Level::TRACE.into()))
        .with(tracing_journald::Layer::new())
        .with(fmt::Layer::new().with_writer(non_blocking));
    tracing::subscriber::

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TornaxO7
Comment options

Answer selected by TornaxO7
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