Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Write An Hourly Log File With Rust

This creates a logger and writes out an hourly file. There's a lot of other options for this and some of the options aren't being used yet. (This page is still a work in progress), but this works

Code

use tracing::{debug, error, info, span, warn, Level};

fn main() {
    let file_appender = tracing_appender::rolling::hourly("/Users/alan/Desktop", "prefix.log");
    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
    tracing_subscriber::fmt().with_writer(non_blocking).init();
    info!["this is info"];
    println!("Hello, world!");
    alfa("yo");
}

#[tracing::instrument]
fn alfa(ping: &str) {
    info!["here"];
    println!("{}", ping);
}

Needs:

  • tracing_appender

  • tracing_subscriber