| 46 | } |
| 47 | |
| 48 | fn log(&self, record: &log::Record) { |
| 49 | // Translate `log`'s levels to `sys`. |
| 50 | let level = match record.metadata().level() { |
| 51 | log::Level::Error => sys::LogLevel::Error, |
| 52 | log::Level::Warn => sys::LogLevel::Warn, |
| 53 | log::Level::Info => sys::LogLevel::Info, |
| 54 | log::Level::Debug => sys::LogLevel::Debug, |
| 55 | log::Level::Trace => sys::LogLevel::Trace, |
| 56 | }; |
| 57 | |
| 58 | // Write the message to the buffer. |
| 59 | let buf = &mut *self.buf.lock().unwrap(); |
| 60 | buf.clear(); |
| 61 | fmt::write(buf, *record.args()).unwrap(); |
| 62 | |
| 63 | // Log the buffer to the console. |
| 64 | sys::console_log(level, Some(record.target()), record.file(), record.line(), buf); |
| 65 | |
| 66 | // If we allocated above `MAX_BUF_SIZE`, make sure we shrink below it. |
| 67 | buf.shrink_to(MAX_BUF_SIZE); |
| 68 | } |
| 69 | |
| 70 | fn flush(&self) {} |
| 71 | } |