mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
simplify logging macros
This commit is contained in:
parent
81661377a8
commit
d31269ebdc
5 changed files with 33 additions and 24 deletions
|
@ -10,5 +10,5 @@ crate-type = ["staticlib"]
|
|||
|
||||
[dependencies]
|
||||
rlibc = "1.0.0" # Low-level functions like memcpy.
|
||||
spin = "0.4.5" # Spinlocks.
|
||||
x86 = "0.8.1" # CPU data structures.
|
||||
spin = "0.4.5" # Spinlocks.
|
||||
x86 = "0.8.1" # CPU data structures.
|
||||
|
|
|
@ -29,17 +29,26 @@ use core::fmt;
|
|||
use spin::Mutex;
|
||||
|
||||
extern {
|
||||
pub fn kputs(s: *const u8) -> i32;
|
||||
pub fn kputchar(c: u8) -> i32;
|
||||
}
|
||||
|
||||
pub struct Console;
|
||||
|
||||
impl fmt::Write for Console {
|
||||
/// print character to the screen
|
||||
fn write_char(&mut self, c: char) -> fmt::Result {
|
||||
let out: u8 = c as u8;
|
||||
unsafe {
|
||||
kputchar(out);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// print string as kernel message.
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
unsafe {
|
||||
kputs(s.as_ptr());
|
||||
}
|
||||
for chars in s.chars() {
|
||||
self.write_char(chars).unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,11 +48,14 @@ mod console;
|
|||
pub use runtime_glue::*;
|
||||
pub use logging::*;
|
||||
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main() {
|
||||
println!("Hello from Rust!");
|
||||
info!("Hello from HermitCore's Rust runtime! v{}", VERSION);
|
||||
|
||||
//info!("hello");
|
||||
//info!("info");
|
||||
//warn!("warning");
|
||||
//debug!("debug");
|
||||
//error!("oops");
|
||||
}
|
||||
|
|
|
@ -64,17 +64,16 @@ macro_rules! info {
|
|||
let current_level = LOGGER.log_level as u8;
|
||||
let cmp_level = LogLevel::INFO as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
println!("[INFO] {}", $fmt);
|
||||
}
|
||||
});
|
||||
if current_level >= cmp_level {
|
||||
println!(concat!("[INFO] ", $fmt));
|
||||
}
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
let current_level = LOGGER.log_level as u8;
|
||||
let cmp_level = LogLevel::INFO as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
print!("[INFO] ")
|
||||
println!($fmt, $($arg)*);
|
||||
println!(concat!("[INFO] ", $fmt), $($arg)*);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ macro_rules! warn {
|
|||
let cmp_level = LogLevel::WARNING as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
println!("[WARNING] {}", $fmt);
|
||||
println!(concat!("[WARNING] ", $fmt));
|
||||
}
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
|
@ -94,8 +93,7 @@ macro_rules! warn {
|
|||
let cmp_level = LogLevel::WARNING as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
print!("[WARNING] ")
|
||||
println!($fmt, $($arg)*);
|
||||
println!(concat!("[WARNING] ", $fmt), $($arg)*);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -107,7 +105,7 @@ macro_rules! error {
|
|||
let cmp_level = LogLevel::ERROR as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
println!("[ERROR] {}", $fmt);
|
||||
println!(concat!("[ERROR] ", $fmt));
|
||||
}
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
|
@ -115,8 +113,7 @@ macro_rules! error {
|
|||
let cmp_level = LogLevel::ERROR as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
print!("[ERROR] ")
|
||||
println!($fmt, $($arg)*);
|
||||
println!(concat!("[ERROR] ", $fmt), $($arg)*);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -128,7 +125,7 @@ macro_rules! debug {
|
|||
let cmp_level = LogLevel::DEBUG as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
println!("[DEBUG] {}", $fmt);
|
||||
println!(concat!("[DEBUG] ", $fmt));
|
||||
}
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
|
@ -136,8 +133,7 @@ macro_rules! debug {
|
|||
let cmp_level = LogLevel::DEBUG as u8;
|
||||
|
||||
if current_level >= cmp_level {
|
||||
print!("[DEBUG] ")
|
||||
println!($fmt, $($arg)*);
|
||||
println!(concat!("[DEBUG] ", $fmt), $($arg)*);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,5 +14,6 @@
|
|||
"no-compiler-rt": true,
|
||||
"archive-format": "gnu"
|
||||
"code-model": "kernel"
|
||||
"relocation-model": "static"
|
||||
"relocation-model": "static"
|
||||
"panic-strategy": "abort"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue