Expand description
Automatic logging for function execution.
This function does the following:
- Output that the task is now running.
- Run the task.
- Clear running output and output that the task is now done.
Whatever the runner returns is returned by this function so you can still use Result and ? if you’re using a closure.
Logging this way actually makes for some very clean code. You can clearly see what is happening in a specific section of your code. It is almost like normal comments but with logging added on!
Examples
To see more examples that you can even run locally please check out the examples directory.
Basic Example
use task_log::task;
let sum = task("Adding 1 and 2", || -> u32 { 1 + 2 });
println!("Sum of 1 and 2 is {}", sum);Error Example
use std::fs;
use std::io::Result;
use task_log::task;
task("Creating and removing file", || -> Result<()> {
let filename = "hello.txt";
fs::write(filename, "foo bar")?;
fs::remove_file(filename)?;
Ok(())
})
.expect("Failed to create and remove the file");