mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-16 17:13:46 -05:00
V3
Many many many changes, honestly just read the release notes
This commit is contained in:
42
src/logging.rs
Normal file
42
src/logging.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
($($arg:tt)*) => ({
|
||||
eprintln!("\x1b[31;1mERROR\x1b[0m {}", format!($($arg)*));
|
||||
std::process::exit(1);
|
||||
})
|
||||
}
|
||||
|
||||
/// This struct mostly exists so we can print stuff without passing debug or raw every time.
|
||||
#[derive(Clone)]
|
||||
pub struct Logger {
|
||||
debug: bool,
|
||||
raw: bool,
|
||||
}
|
||||
|
||||
impl Logger {
|
||||
pub fn new(debug: bool, raw: bool) -> Self {
|
||||
Self { debug, raw }
|
||||
}
|
||||
|
||||
pub fn warn(&self, msg: impl AsRef<str>) {
|
||||
if !self.raw {
|
||||
eprintln!("\x1b[33;1m WARN\x1b[0m {}", msg.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn info(&self, msg: impl AsRef<str>) {
|
||||
if !self.raw {
|
||||
println!("\x1b[36;1m INFO\x1b[0m {}", msg.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debug(&self, msg: impl AsRef<str>) {
|
||||
if self.debug {
|
||||
println!("\x1b[35;1mDEBUG\x1b[0m {}", msg.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_raw(&mut self, raw: bool) {
|
||||
self.raw = raw
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user