From 41d8af754a5656c20ad492878bf77b472a1f8b73 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 13 Jul 2020 00:52:06 +0200 Subject: [PATCH] runtime: retain BufferLogger within LOGGER --- src/runtime/src/logger.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/src/logger.rs b/src/runtime/src/logger.rs index 9862bf3..ef32117 100644 --- a/src/runtime/src/logger.rs +++ b/src/runtime/src/logger.rs @@ -40,7 +40,7 @@ pub struct BufferLogger { uart_filter: Cell } -static mut LOGGER: *const BufferLogger = 0 as *const _; +static mut LOGGER: Option = None; impl BufferLogger { pub fn new(buffer: &'static mut [u8]) -> BufferLogger { @@ -50,10 +50,10 @@ impl BufferLogger { } } - pub fn register(&self, f: F) { + pub fn register(self, f: F) { unsafe { - LOGGER = self; - log::set_logger(&*LOGGER) + LOGGER = Some(self); + log::set_logger(LOGGER.as_ref().unwrap()) .expect("global logger can only be initialized once"); } log::set_max_level(LevelFilter::Info); @@ -61,7 +61,7 @@ impl BufferLogger { } pub fn with R>(f: F) -> R { - f(unsafe { &*LOGGER }) + f(unsafe { LOGGER.as_ref().expect("with logger") }) } pub fn buffer<'a>(&'a self) -> Result, ()> {