Commit a53beb77 authored by Stefan Lankes's avatar Stefan Lankes
Browse files

simplify logging macros

parent dab6492f
......@@ -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,19 +29,28 @@ 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 string as kernel message.
fn write_str(&mut self, s: &str) -> fmt::Result {
/// print character to the screen
fn write_char(&mut self, c: char) -> fmt::Result {
let out: u8 = c as u8;
unsafe {
kputs(s.as_ptr());
kputchar(out);
}
Ok(())
}
/// print string as kernel message.
fn write_str(&mut self, s: &str) -> fmt::Result {
for chars in s.chars() {
self.write_char(chars).unwrap();
}
Ok(())
}
}
pub static CONSOLE: Mutex<Console> = Mutex::new(Console);
......@@ -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"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment