pub async fn init(
log_file: Option<&str>,
level: Option<LevelFilter>,
extra_levels: Option<HashMap<&str, LevelFilter>>,
) -> Result<(InitContext, Receiver<i32>)>
Expand description
The main function. Call it as soon as possible in your program. It returns the context and the channel to listen the exit requests
use wixet_bootstrap::init;
use log::info;
#[tokio::main]
async fn main() {
info!("This log line will be ignored because the logger is not configured yet");
let (closer, exit) = init(Some("output.log")).await?; //If you provide None, it simple will not write a log file (just output)
info!("Hello to my application!")
// Do may awesome stuff spawing tokio tasks
// I use select here because it is common to listen for multiple signals, but you can just await the `exit` if not
tokio::select!{
_ = exit.recv_async() => {
info!("Shutdown process started");
// Do your friendly stop process here
// This code is run when ctrl+c or any other kill interrupt is received
}
};
// A friendly shutdown by deinitializing all "init" stuff.
closer.stop().await?;
info!("Bye");
}