use hurl_core::text::{Format, Style, StyledString};
pub struct BaseLogger {
format: Format,
verbose: bool,
}
impl BaseLogger {
pub fn new(color: bool, verbose: bool) -> BaseLogger {
let format = if color { Format::Ansi } else { Format::Plain };
BaseLogger { format, verbose }
}
pub fn info(&self, message: &str) {
eprintln!("{message}");
}
pub fn debug(&self, message: &str) {
if !self.verbose {
return;
}
let mut s = StyledString::new();
s.push_with("*", Style::new().blue().bold());
if !message.is_empty() {
s.push(&format!(" {message}"));
}
eprintln!("{}", s.to_string(self.format));
}
pub fn error(&self, message: &str) {
if message.is_empty() {
return;
}
let mut s = StyledString::new();
s.push_with("error", Style::new().red().bold());
s.push(": ");
s.push_with(message, Style::new().bold());
eprintln!("{}", s.to_string(self.format));
}
}