mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
30 lines
683 B
Rust
30 lines
683 B
Rust
mod level;
|
|
use level::Level;
|
|
|
|
pub struct Debug(Vec<Level>);
|
|
|
|
impl Debug {
|
|
pub fn init(levels: &str) -> anyhow::Result<Self> {
|
|
let mut l = Vec::with_capacity(levels.len());
|
|
for s in levels.to_lowercase().chars() {
|
|
l.push(Level::parse(s)?);
|
|
}
|
|
Ok(Self(l))
|
|
}
|
|
|
|
pub fn error(&self, message: &str) {
|
|
if self.0.contains(&Level::Error) {
|
|
eprintln!("[{}] [error] {message}", now());
|
|
}
|
|
}
|
|
|
|
pub fn info(&self, message: &str) {
|
|
if self.0.contains(&Level::Info) {
|
|
println!("[{}] [info] {message}", now());
|
|
}
|
|
}
|
|
}
|
|
|
|
fn now() -> String {
|
|
chrono::Local::now().to_rfc3339()
|
|
}
|