forked from M-Labs/artiq-zynq
runtime: retain BufferLogger within LOGGER
This commit is contained in:
parent
9611be657c
commit
41d8af754a
|
@ -40,7 +40,7 @@ pub struct BufferLogger {
|
||||||
uart_filter: Cell<LevelFilter>
|
uart_filter: Cell<LevelFilter>
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut LOGGER: *const BufferLogger = 0 as *const _;
|
static mut LOGGER: Option<BufferLogger> = None;
|
||||||
|
|
||||||
impl BufferLogger {
|
impl BufferLogger {
|
||||||
pub fn new(buffer: &'static mut [u8]) -> 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 {
|
unsafe {
|
||||||
LOGGER = self;
|
LOGGER = Some(self);
|
||||||
log::set_logger(&*LOGGER)
|
log::set_logger(LOGGER.as_ref().unwrap())
|
||||||
.expect("global logger can only be initialized once");
|
.expect("global logger can only be initialized once");
|
||||||
}
|
}
|
||||||
log::set_max_level(LevelFilter::Info);
|
log::set_max_level(LevelFilter::Info);
|
||||||
|
@ -61,7 +61,7 @@ impl BufferLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with<R, F: FnOnce(&BufferLogger) -> R>(f: F) -> R {
|
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>, ()> {
|
pub fn buffer<'a>(&'a self) -> Result<LogBufferRef<'a>, ()> {
|
||||||
|
|
Loading…
Reference in New Issue