1 unstable release
0.1.3 | May 2, 2023 |
---|---|
0.1.2 |
|
0.1.1 |
|
0.1.0 |
|
#20 in #spinner
35 downloads per month
17KB
129 lines
SLL
A Simple Logging Library
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();
}
Dependencies
~0–9.5MB
~42K SLoC