mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
initial commit
This commit is contained in:
parent
d3661f8865
commit
ab625aa96a
14 changed files with 533 additions and 0 deletions
33
src/session/debug.rs
Normal file
33
src/session/debug.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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() -> u128 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue