From b1a3695dfb037f12809e9d652748da09014a79ad Mon Sep 17 00:00:00 2001 From: WangRunji Date: Thu, 12 Jul 2018 23:31:54 +0800 Subject: [PATCH] Prettify log output --- src/arch/x86_64/driver/vga.rs | 2 +- src/lib.rs | 6 +++--- src/{io/mod.rs => logging.rs} | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) rename src/{io/mod.rs => logging.rs} (92%) diff --git a/src/arch/x86_64/driver/vga.rs b/src/arch/x86_64/driver/vga.rs index 1f5139e..7ef8720 100644 --- a/src/arch/x86_64/driver/vga.rs +++ b/src/arch/x86_64/driver/vga.rs @@ -4,7 +4,7 @@ use core::fmt; use spin::Mutex; use volatile::Volatile; use x86_64::instructions::port::Port; -use io::Color; +use logging::Color; pub const VGA_BUFFER: Unique = unsafe { Unique::new_unchecked((KERNEL_OFFSET + 0xb8000) as *mut _) diff --git a/src/lib.rs b/src/lib.rs index 497454c..96a2ced 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ pub use arch::other_main; use linked_list_allocator::LockedHeap; #[macro_use] // print! -mod io; +mod logging; mod memory; mod lang; mod util; @@ -89,7 +89,7 @@ fn timer_interrupt() { #[no_mangle] #[cfg(target_arch = "riscv")] pub extern fn rust_main() -> ! { - io::init(); + logging::init(); arch::init(); process::init(); info!("RISCV init end"); @@ -104,7 +104,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! { // ATTENTION: we have a very small stack and no guard page println!("Hello World{}", "!"); - io::init(); + logging::init(); arch::init(multiboot_information_address); process::init(); diff --git a/src/io/mod.rs b/src/logging.rs similarity index 92% rename from src/io/mod.rs rename to src/logging.rs index 96b4277..f59c435 100644 --- a/src/io/mod.rs +++ b/src/logging.rs @@ -17,7 +17,7 @@ pub fn init() { macro_rules! print { ($($arg:tt)*) => ({ - $crate::io::print(format_args!($($arg)*)); + $crate::logging::print(format_args!($($arg)*)); }); } @@ -84,7 +84,9 @@ impl Log for SimpleLogger { "rust_ucore::process::scheduler::rr", ]; if self.enabled(record.metadata()) && !DISABLED_TARGET.contains(&record.target()) { - print_in_color(format_args!("[{}] {}\n", record.target(), record.args()), Color::from(record.level())); +// let target = record.target(); +// let begin = target.as_bytes().iter().rposition(|&c| c == b':').map(|i| i + 1).unwrap_or(0); + print_in_color(format_args!("[{:>5}] {}\n", record.level(), record.args()), Color::from(record.level())); } } fn flush(&self) {}