/
log.rs
46 lines (41 loc) · 1.89 KB
/
log.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use prologue_logger::{Entry, Task, PrologueLogger};
fn main() -> prologue_logger::error::Result<()> {
let target_list = PrologueLogger::init()?;
target_list.create_target("log")?;
target_list.create_target("")?;
Entry::new_warning("starting `log.rs` -- the following is NOT generated by `cargo`")
.log("log");
Task::new("Running", "example `log.rs`")
.log("log");
Entry::new_warning("this is a warning line")
.named_source("examples/log.rs", 8, 36)
.new_line(8, " let entry = Entry::new_warning(\"this is a warning line\")")
.annotate_help(9, 5, "this is the variable")?
.annotate_help(17, 18, "this is the invoking function")?
.annotate_note(36, 24, "this is the text")?
.new_line(9, " .bright()")
.new_line(10, " .source(source)")
.new_line(11, " .forward_to_stderr();")
.annotate_warn(6, 17, "this function does not increase the warning count")?
.note("this is not the actual source code")
.help("to see the actual source code for this example,\nsee `examples/log.rs`")
.note("this output is generated by `prologue-logger` and NOT by `cargo`")
.finish()
.log("log");
let target = target_list.find("log").unwrap();
target.if_errors(|count| {
Entry::new_warning(format!("Could not run `example/log.rs` due to {} previous error{}", count, if count > 1 { "s" } else { "" }))
.log("");
Ok(())
})?;
target.if_warnings(|count| {
Entry::new_warning(format!("`example/log.rs` (example) generated {} warning{}", count, if count > 1 { "s" } else { "" }))
.log("");
Ok(())
})?;
// No errors generated.
assert_eq!(target.error_count(), 0);
// Only two warnings logged (the third one was generated and displayed, but not logged).
assert_eq!(target.warning_count(), 2);
Ok(())
}