use std::io::Write;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Level {
Info,
Warn,
Error,
}
impl Level {
#[inline]
const fn tag(self) -> &'static str {
match self {
Level::Info => "INFO",
Level::Warn => "WARN",
Level::Error => "ERROR",
}
}
}
#[doc(hidden)]
#[inline]
pub fn log(level: Level, args: std::fmt::Arguments<'_>) {
if matches!(level, Level::Error) {
let mut out = std::io::stderr().lock();
let _ = writeln!(out, "[yog] [{}] {}", level.tag(), args);
} else {
let mut out = std::io::stdout().lock();
let _ = writeln!(out, "[yog] [{}] {}", level.tag(), args);
}
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
$crate::log($crate::Level::Info, ::core::format_args!($($arg)*))
};
}
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
$crate::log($crate::Level::Warn, ::core::format_args!($($arg)*))
};
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
$crate::log($crate::Level::Error, ::core::format_args!($($arg)*))
};
}