69 lines
1.7 KiB
Rust
69 lines
1.7 KiB
Rust
use crate::sbi::console_print;
|
|
use core::fmt;
|
|
use core::fmt::Write;
|
|
|
|
struct Stdout;
|
|
|
|
impl Write for Stdout {
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
for c in s.chars() {
|
|
console_print(c as usize);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
Stdout.write_fmt(args).unwrap()
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! print {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!($fmt $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! println {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_error {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!("\x1b[31m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_warning {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!("\x1b[93m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_information {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!("\x1b[34m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_debug {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!("\x1b[32m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_trace {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!("\x1b[90m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?));
|
|
}
|
|
}
|