-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
1 addition
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,13 @@ | ||
#![allow(clippy::large_enum_variant)] | ||
#![allow(clippy::new_ret_no_self)] | ||
|
||
#[macro_use] | ||
extern crate log; | ||
|
||
mod cmath; | ||
#[cfg(not(feature = "tcp"))] | ||
mod dummy; | ||
|
||
use log::{set_logger, set_max_level, LevelFilter, Metadata, Record}; | ||
|
||
/// Data structure to filter kernel messages | ||
struct SysLogger; | ||
|
||
impl log::Log for SysLogger { | ||
fn enabled(&self, _: &Metadata) -> bool { | ||
true | ||
} | ||
|
||
fn flush(&self) { | ||
// nothing to do | ||
} | ||
|
||
fn log(&self, record: &Record) { | ||
if self.enabled(record.metadata()) { | ||
println!("[{}] {}", record.level(), record.args()); | ||
} | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn sys_network_init() -> i32 { | ||
set_logger(&SysLogger).expect("Can't initialize logger"); | ||
// Determines LevelFilter at compile time | ||
let log_level: Option<&'static str> = option_env!("HERMIT_LOG_LEVEL_FILTER"); | ||
let max_level: LevelFilter = match log_level { | ||
Some("Error") => LevelFilter::Error, | ||
Some("Debug") => LevelFilter::Debug, | ||
Some("Off") => LevelFilter::Off, | ||
Some("Trace") => LevelFilter::Trace, | ||
Some("Warn") => LevelFilter::Warn, | ||
Some("Info") => LevelFilter::Info, | ||
_ => LevelFilter::Info, | ||
}; | ||
set_max_level(max_level); | ||
// nothing to do | ||
|
||
0 | ||
} |