Crates.io | sll |
lib.rs | sll |
version | 0.1.3 |
source | src |
created_at | 2023-05-02 11:24:00.45005 |
updated_at | 2023-05-02 11:44:50.552666 |
description | A simple logging library. |
homepage | |
repository | |
max_upload_size | |
id | 854450 |
size | 21,787 |
SLL provides simple functions in rust in order to do basic logging.
Log!()
The log!()
macro takes in the message (String
or &str
) and optionally a LogLevel
: Critical
, Error
, Warning
, Info
, Debug
and Notice
.
Example code:
use sll;
fn main() {
sll:log!("Criticall error", LogLevel::CRITICAL);
sll:log!("Error", LogLevel::ERROR);
sll:log!("Warning", LogLevel::WARNING);
sll:log!("Information", LogLevel::INFO);
sll:log!("Debugging is hard", LogLevel::DEBUG);
sll:log!("Hello", LogLevel::NOTICE);
}
section!()
, task!()
and prompt!()
A section is used to describe a major part of the code, for example in a program for a restaurant robot, make starter, make dinner and make dessert are sections.
Tasks are used to describe smaller pieces of the code in the example a task would be something like: peel carrots, cut carrots, ...
A Prompt is probably the most straigtforward an already known concept. You ask for user input over the command line.
Sections, tasks and prompts all have one required argument, a message, and one optional argument, a depth.
The depth can be used to specify sub-sections or sub-tasks a sub task has a higher depth than it's parent task.
Example code:
use sll;
fn main() {
let p = sll:prompt!("Ready for dinner");
sll:section!("Make starter");
sll:task!("Boil water");
sll:task!("Add bouillon");
sll:section!("Make dinner");
sll:section!("Cut greens", 1);
sll:task!("Carrot", 1);
sll:task!("Peel carrot", 2);
sll:task!("Cut carrot", 2);
sll:task!("Potato", 1);
sll:task!("Peel potato", 2);
sll:task!("Cut potato", 2);
// TODO: rest of meal
}
Spinner
and Progress
Spinners and progressbars are both used to convey the message that the computer is thinking real hard.
Spinners should be used when you don't know how long a loop is going to take.
When you do know how long (how many iterations) a loop is going to take, use a progressbar.
Example code:
use ssl;
fn main() {
let spinner = ssl::Spinner::new();
loop {
spinner.update();
let result = do_something();
if result.done {
break;
}
}
spinner.release();
let progress = ssl::Progress::new(100, 0);
for i in 1..101 {
do_something(i);
progress.update(1);
}
progress.release();
}