๋ก๊น
log
ํฌ๋ ์ดํธ์ ๋ก๊น
๋งคํฌ๋ก๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉด ์ข์ต๋๋ค. ์ด๋ Log
ํธ๋ ์์ ๊ตฌํํ๋ฉด ๋ฉ๋๋ค.
use crate::pl011::Uart; use core::fmt::Write; use log::{LevelFilter, Log, Metadata, Record, SetLoggerError}; use spin::mutex::SpinMutex; static LOGGER: Logger = Logger { uart: SpinMutex::new(None), }; struct Logger { uart: SpinMutex<Option<Uart>>, } impl Log for Logger { fn enabled(&self, _metadata: &Metadata) -> bool { true } fn log(&self, record: &Record) { writeln!( self.uart.lock().as_mut().unwrap(), "[{}] {}", record.level(), record.args() ) .unwrap(); } fn flush(&self) {} } /// Initialises UART logger. pub fn init(uart: Uart, max_level: LevelFilter) -> Result<(), SetLoggerError> { LOGGER.uart.lock().replace(uart); log::set_logger(&LOGGER)?; log::set_max_level(max_level); Ok(()) }
log
ํจ์ ์์์unwrap
ํ๋ ๊ฒ์ ๊ด์ฐฎ์ต๋๋ค.. ์๋ํ๋ฉดset_logger
๋ฅผ ํธ์ถํ๊ธฐ ์ ์LOGGER
๋ฅผ ์ด๊ธฐํํ๊ธฐ ๋๋ฌธ์ ๋๋ค.