|
@@ -1,7 +1,17 @@
|
|
use core::fmt::{self, Write};
|
|
use core::fmt::{self, Write};
|
|
|
|
|
|
|
|
+use alloc::string::ToString;
|
|
|
|
+
|
|
use super::lib_ui::textui::{textui_putstr, FontColor};
|
|
use super::lib_ui::textui::{textui_putstr, FontColor};
|
|
|
|
|
|
|
|
+use crate::{
|
|
|
|
+ filesystem::procfs::{
|
|
|
|
+ kmsg::KMSG,
|
|
|
|
+ log::{LogLevel, LogMessage},
|
|
|
|
+ },
|
|
|
|
+ time::TimeSpec,
|
|
|
|
+};
|
|
|
|
+
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! print {
|
|
macro_rules! print {
|
|
($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
|
|
($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
|
|
@@ -30,14 +40,15 @@ macro_rules! printk_color {
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! kdebug {
|
|
macro_rules! kdebug {
|
|
($($arg:tt)*) => {
|
|
($($arg:tt)*) => {
|
|
|
|
+ $crate::libs::printk::Logger.log(7,format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("[ DEBUG ] ({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)))
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("[ DEBUG ] ({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)))
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! kinfo {
|
|
macro_rules! kinfo {
|
|
($($arg:tt)*) => {
|
|
($($arg:tt)*) => {
|
|
|
|
+ $crate::libs::printk::Logger.log(6,format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("[ INFO ] ({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)))
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("[ INFO ] ({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -45,6 +56,7 @@ macro_rules! kinfo {
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! kwarn {
|
|
macro_rules! kwarn {
|
|
($($arg:tt)*) => {
|
|
($($arg:tt)*) => {
|
|
|
|
+ $crate::libs::printk::Logger.log(4,format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::YELLOW, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ WARN ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::YELLOW, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ WARN ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
}
|
|
}
|
|
@@ -53,6 +65,7 @@ macro_rules! kwarn {
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! kerror {
|
|
macro_rules! kerror {
|
|
($($arg:tt)*) => {
|
|
($($arg:tt)*) => {
|
|
|
|
+ $crate::libs::printk::Logger.log(3,format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::RED, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ ERROR ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::RED, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ ERROR ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
}
|
|
}
|
|
@@ -61,6 +74,7 @@ macro_rules! kerror {
|
|
#[macro_export]
|
|
#[macro_export]
|
|
macro_rules! kBUG {
|
|
macro_rules! kBUG {
|
|
($($arg:tt)*) => {
|
|
($($arg:tt)*) => {
|
|
|
|
+ $crate::libs::printk::Logger.log(1,format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::RED, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ BUG ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::lib_ui::textui::FontColor::RED, $crate::libs::lib_ui::textui::FontColor::BLACK, "[ BUG ] ");
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
$crate::libs::printk::PrintkWriter.__write_fmt(format_args!("({}:{})\t {}\n", file!(), line!(),format_args!($($arg)*)));
|
|
}
|
|
}
|
|
@@ -97,3 +111,17 @@ impl fmt::Write for PrintkWriter {
|
|
pub fn __printk(args: fmt::Arguments) {
|
|
pub fn __printk(args: fmt::Arguments) {
|
|
PrintkWriter.write_fmt(args).unwrap();
|
|
PrintkWriter.write_fmt(args).unwrap();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+pub struct Logger;
|
|
|
|
+
|
|
|
|
+impl Logger {
|
|
|
|
+ pub fn log(&self, log_level: usize, message: fmt::Arguments) {
|
|
|
|
+ if unsafe { !KMSG.is_none() } {
|
|
|
|
+ let timestamp: TimeSpec = TimeSpec::now();
|
|
|
|
+ let log_level = LogLevel::from(log_level.clone());
|
|
|
|
+ let log_message = LogMessage::new(timestamp, log_level, message.to_string());
|
|
|
|
+
|
|
|
|
+ unsafe { KMSG.as_ref().unwrap().lock_irqsave().push(log_message) };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|