6dc75f0c5d
This patch adds tests for Rust 1.54.0, 1.55.0 and 1.56.0. To make the tests pass, we have to take care of some changes like more details elements and changed heading levels. To make it easier to generate the tests for new Rust versions, we also add two bash scripts that take care of that.
64 lines
1.7 KiB
Plaintext
64 lines
1.7 KiB
Plaintext
---
|
|
source: tests/output.rs
|
|
expression: "get_stdout(&[\"-e\", item])"
|
|
---
|
|
log Module log rusty-man
|
|
|
|
EXAMPLES
|
|
Example 1 of 4
|
|
use log::{info, warn};
|
|
|
|
pub fn shave_the_yak(yak: &mut Yak) {
|
|
info!(target: "yak_events", "Commencing yak shaving for {:?}", yak);
|
|
|
|
loop {
|
|
match find_a_razor() {
|
|
Ok(razor) => {
|
|
info!("Razor located: {}", razor);
|
|
yak.shave(razor);
|
|
break;
|
|
}
|
|
Err(err) => {
|
|
warn!("Unable to locate a razor: {}, retrying", err);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Example 2 of 4
|
|
use log::{Record, Level, Metadata};
|
|
|
|
struct SimpleLogger;
|
|
|
|
impl log::Log for SimpleLogger {
|
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
|
metadata.level() <= Level::Info
|
|
}
|
|
|
|
fn log(&self, record: &Record) {
|
|
if self.enabled(record.metadata()) {
|
|
println!("{} - {}", record.level(), record.args());
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
Example 3 of 4
|
|
use log::{SetLoggerError, LevelFilter};
|
|
|
|
static LOGGER: SimpleLogger = SimpleLogger;
|
|
|
|
pub fn init() -> Result<(), SetLoggerError> {
|
|
log::set_logger(&LOGGER)
|
|
.map(|()| log::set_max_level(LevelFilter::Info))
|
|
}
|
|
|
|
Example 4 of 4
|
|
pub fn init() -> Result<(), SetLoggerError> {
|
|
log::set_boxed_logger(Box::new(SimpleLogger))
|
|
.map(|()| log::set_max_level(LevelFilter::Info))
|
|
}
|
|
|
|
|