diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index 806afa09d70cd7d809d1b06eac90437ad16928a9..f901b0056d7863cb7be09f9e2fe541017fdbad89 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -10,7 +10,7 @@ pub(crate) struct Scheduler { runtime: Arc, polling: PollingClient, scheduler_id: u32, - debug_logging: bool, + log_level: LogLevel, } pub(crate) struct SchedulerCtx<'a> { @@ -18,22 +18,29 @@ pub(crate) struct SchedulerCtx<'a> { pub polling: &'a PollingClient, pub id: u32, pub comp: u32, - pub logging_enabled: bool, + pub log_level: LogLevel, } impl<'a> SchedulerCtx<'a> { - pub fn new(runtime: &'a RuntimeInner, polling: &'a PollingClient, id: u32, logging_enabled: bool) -> Self { + pub fn new(runtime: &'a RuntimeInner, polling: &'a PollingClient, id: u32, log_level: LogLevel) -> Self { return Self { runtime, polling, id, comp: 0, - logging_enabled, + log_level, } } - pub(crate) fn log(&self, text: &str) { - if self.logging_enabled { + pub(crate) fn debug(&self, text: &str) { + // TODO: Probably not always use colour + if self.log_level >= LogLevel::Debug { + println!("[s:{:02}, c:{:03}] \x1b[0;34m{}\x1b[0m", self.id, self.comp, text); + } + } + + pub(crate) fn info(&self, text: &str) { + if self.log_level >= LogLevel::Info { println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text); } } @@ -47,12 +54,12 @@ impl<'a> SchedulerCtx<'a> { impl Scheduler { // public interface to thread - pub fn new(runtime: Arc, polling: PollingClient, scheduler_id: u32, debug_logging: bool) -> Self { - return Scheduler{ runtime, polling, scheduler_id, debug_logging } + pub fn new(runtime: Arc, polling: PollingClient, scheduler_id: u32, log_level: LogLevel) -> Self { + return Scheduler{ runtime, polling, scheduler_id, log_level } } pub fn run(&mut self) { - let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, &self.polling, self.scheduler_id, self.debug_logging); + let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, &self.polling, self.scheduler_id, self.log_level); 'run_loop: loop { // Wait until we have something to do (or need to quit)