Crates.io | task_log |
lib.rs | task_log |
version | 0.1.6 |
source | src |
created_at | 2022-02-27 19:53:18.165595 |
updated_at | 2022-11-27 22:47:23.178266 |
description | Task based logging |
homepage | |
repository | https://github.com/gleich/task_log |
max_upload_size | |
id | 540486 |
size | 530,172 |
task_log is a task-based logger.
Just add task_log = 0.1.6
to your Cargo.toml's dependency
section.
Let's get right to the chase. What does using this logger look like?
use std::io::Result;
use std::time::Duration;
use std::{fs, thread};
use task_log::task;
fn main() {
task("Creating and removing file", || -> Result<()> {
let filename = "hello.txt";
fs::write(filename, "foo bar")?;
thread::sleep(Duration::from_secs(2));
fs::remove_file(filename)?;
Ok(())
})
.expect("Failed to create and delete the file");
}
As you can see we provide a task to run and a description of what that task is doing. When we run this code we get the following output.
To see more examples see the examples folder.
You can configure task_log's task
function using a struct called ConfigBuilder
. Here is an example of using ConfigBuilder
:
use std::thread;
use std::time::Duration;
use task_log::{task, ConfigBuilder};
fn main() {
ConfigBuilder::new()
.duration(false)
.apply()
.expect("Failed to setup configuration");
let sum = task("Adding 1 and 2", || -> u32 {
let result = 1 + 2;
thread::sleep(Duration::from_secs(2));
result
});
println!("Sum is {}", sum)
}
To learn more about ConfigBuilder
please reference the docs.rs documentation.
Here are some features I'm hoping to implement in the future:
RUNNING
prefix.