use std::{
    fmt::Arguments,
    io::{self, Write},
};

use crate::log::{Log, LogLevel};

/// A very simple logger that prints to `stdout` or `stderr`
#[derive(Debug)]
pub struct CliLogger;

impl Log for CliLogger {
    fn log_unchecked(&self, level: LogLevel, msg: Arguments) {
        let output: &mut dyn Write = match level {
            LogLevel::Error | LogLevel::Warn => &mut io::stderr(),
            _ => &mut io::stdout(),
        };

        match level {
            LogLevel::Info => {}
            _ => {
                let _ = write!(output, "[{level}]: ");
            }
        }
        let _ = output.write_fmt(msg);
        let _ = output.write(b"\n");
    }
}
