runtime: retain BufferLogger within LOGGER

This commit is contained in:
Astro 2020-07-13 00:52:06 +02:00
parent 9611be657c
commit 41d8af754a
1 changed files with 5 additions and 5 deletions

View File

@ -40,7 +40,7 @@ pub struct BufferLogger {
uart_filter: Cell<LevelFilter>
}
static mut LOGGER: *const BufferLogger = 0 as *const _;
static mut LOGGER: Option<BufferLogger> = None;
impl BufferLogger {
pub fn new(buffer: &'static mut [u8]) -> BufferLogger {
@ -50,10 +50,10 @@ impl BufferLogger {
}
}
pub fn register<F: FnOnce()>(&self, f: F) {
pub fn register<F: FnOnce()>(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: FnOnce(&BufferLogger) -> R>(f: F) -> R {
f(unsafe { &*LOGGER })
f(unsafe { LOGGER.as_ref().expect("with logger") })
}
pub fn buffer<'a>(&'a self) -> Result<LogBufferRef<'a>, ()> {