add logger
This commit is contained in:
parent
7c855d7f5f
commit
168c2ddf0a
@ -5,6 +5,7 @@ use util::mem_util::from_untrusted::*;
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn libos_boot(path_buf: *const c_char, argv: *const *const c_char) -> i32 {
|
pub extern "C" fn libos_boot(path_buf: *const c_char, argv: *const *const c_char) -> i32 {
|
||||||
|
util::log::init();
|
||||||
let (path, args) = match parse_arguments(path_buf, argv) {
|
let (path, args) = match parse_arguments(path_buf, argv) {
|
||||||
Ok(path_and_args) => path_and_args,
|
Ok(path_and_args) => path_and_args,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -27,6 +27,7 @@ pub extern "C" fn dispatch_syscall(
|
|||||||
arg4: isize,
|
arg4: isize,
|
||||||
arg5: isize,
|
arg5: isize,
|
||||||
) -> isize {
|
) -> isize {
|
||||||
|
debug!("syscall {}: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}, {:#x}", num, arg0, arg1, arg2, arg3, arg4, arg5);
|
||||||
let ret = match num {
|
let ret = match num {
|
||||||
SYS_open => do_open(arg0 as *const i8, arg1 as u32, arg2 as u32),
|
SYS_open => do_open(arg0 as *const i8, arg1 as u32, arg2 as u32),
|
||||||
SYS_close => do_close(arg0 as FileDesc),
|
SYS_close => do_close(arg0 as FileDesc),
|
||||||
|
88
src/libos/src/util/log.rs
Normal file
88
src/libos/src/util/log.rs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
use log::*;
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
static LOGGER: SimpleLogger = SimpleLogger;
|
||||||
|
log::set_logger(&LOGGER).unwrap();
|
||||||
|
log::set_max_level(match option_env!("LOG") {
|
||||||
|
Some("error") => LevelFilter::Error,
|
||||||
|
Some("warn") => LevelFilter::Warn,
|
||||||
|
Some("info") => LevelFilter::Info,
|
||||||
|
Some("debug") => LevelFilter::Debug,
|
||||||
|
Some("trace") => LevelFilter::Trace,
|
||||||
|
_ => LevelFilter::Off,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SimpleLogger;
|
||||||
|
|
||||||
|
impl Log for SimpleLogger {
|
||||||
|
fn enabled(&self, _metadata: &Metadata) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
fn log(&self, record: &Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
let color = Color::from(record.level());
|
||||||
|
let (show, code) = color.to_console_code();
|
||||||
|
println!("\u{1B}[{};{}m[{:>5}] {}\u{1B}[0m",
|
||||||
|
show, code + 30, record.level(), record.args());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn flush(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Level> for Color {
|
||||||
|
fn from(level: Level) -> Self {
|
||||||
|
match level {
|
||||||
|
Level::Error => Color::Red,
|
||||||
|
Level::Warn => Color::Yellow,
|
||||||
|
Level::Info => Color::Blue,
|
||||||
|
Level::Debug => Color::Green,
|
||||||
|
Level::Trace => Color::DarkGray,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum Color {
|
||||||
|
Black = 0,
|
||||||
|
Blue = 1,
|
||||||
|
Green = 2,
|
||||||
|
Cyan = 3,
|
||||||
|
Red = 4,
|
||||||
|
Magenta = 5,
|
||||||
|
Brown = 6,
|
||||||
|
LightGray = 7,
|
||||||
|
DarkGray = 8,
|
||||||
|
LightBlue = 9,
|
||||||
|
LightGreen = 10,
|
||||||
|
LightCyan = 11,
|
||||||
|
LightRed = 12,
|
||||||
|
Pink = 13,
|
||||||
|
Yellow = 14,
|
||||||
|
White = 15,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Color {
|
||||||
|
fn to_console_code(&self) -> (u8, u8) {
|
||||||
|
match self {
|
||||||
|
Color::Black => (0, 0),
|
||||||
|
Color::Blue => (0, 4),
|
||||||
|
Color::Green => (0, 2),
|
||||||
|
Color::Cyan => (0, 6),
|
||||||
|
Color::Red => (0, 1),
|
||||||
|
Color::Magenta => (0, 5),
|
||||||
|
Color::Brown => (0, 3),
|
||||||
|
Color::LightGray => (1, 7),
|
||||||
|
Color::DarkGray => (0, 7),
|
||||||
|
Color::LightBlue => (1, 4),
|
||||||
|
Color::LightGreen => (1, 2),
|
||||||
|
Color::LightCyan => (1, 6),
|
||||||
|
Color::LightRed => (1, 1),
|
||||||
|
Color::Pink => (1, 5),
|
||||||
|
Color::Yellow => (1, 3),
|
||||||
|
Color::White => (1, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,3 +3,4 @@ use super::*;
|
|||||||
pub mod mem_util;
|
pub mod mem_util;
|
||||||
pub mod mpx_util;
|
pub mod mpx_util;
|
||||||
pub mod ring_buf;
|
pub mod ring_buf;
|
||||||
|
pub mod log;
|
||||||
|
Loading…
Reference in New Issue
Block a user