diff --git a/artiq/firmware/Cargo.lock b/artiq/firmware/Cargo.lock index 6a04d73c2..9f6e3a821 100644 --- a/artiq/firmware/Cargo.lock +++ b/artiq/firmware/Cargo.lock @@ -41,7 +41,7 @@ dependencies = [ "board 0.0.0", "build_artiq 0.0.0", "build_misoc 0.0.0", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -81,6 +81,11 @@ name = "cc" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "compiler_builtins" version = "0.1.0" @@ -107,7 +112,7 @@ dependencies = [ "build_misoc 0.0.0", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "std_artiq 0.0.0", ] @@ -157,6 +162,14 @@ name = "log" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "log" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log_buffer" version = "1.1.0" @@ -167,7 +180,7 @@ name = "logger_artiq" version = "0.0.0" dependencies = [ "board 0.0.0", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -183,7 +196,7 @@ dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dyld 0.0.0", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "std_artiq 0.0.0", ] @@ -202,7 +215,7 @@ dependencies = [ "cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "drtioaux 0.0.0", "fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "logger_artiq 0.0.0", "proto 0.0.0", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=507d2fe)", @@ -228,7 +241,7 @@ dependencies = [ "build_artiq 0.0.0", "build_misoc 0.0.0", "drtioaux 0.0.0", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "logger_artiq 0.0.0", "std_artiq 0.0.0", ] @@ -272,6 +285,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum build_const 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e90dc84f5e62d2ebe7676b83c22d33b6db8bd27340fb6ffbff0a364efa0cb9c9" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum compiler_builtins 0.1.0 (git+https://github.com/m-labs/compiler-builtins?rev=1c765ad)" = "" "checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7" "checksum cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a" @@ -279,6 +293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" +"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493" "checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" diff --git a/artiq/firmware/libboard_artiq/Cargo.toml b/artiq/firmware/libboard_artiq/Cargo.toml index 2c92b6050..d666b3ef0 100644 --- a/artiq/firmware/libboard_artiq/Cargo.toml +++ b/artiq/firmware/libboard_artiq/Cargo.toml @@ -14,7 +14,7 @@ build_artiq = { path = "../libbuild_artiq" } [dependencies] bitflags = "1.0" -log = { version = "0.3", default-features = false } +log = { version = "0.4", default-features = false } board = { path = "../libboard" } [features] diff --git a/artiq/firmware/libdrtioaux/Cargo.toml b/artiq/firmware/libdrtioaux/Cargo.toml index 515c15e29..6c4842148 100644 --- a/artiq/firmware/libdrtioaux/Cargo.toml +++ b/artiq/firmware/libdrtioaux/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" build_misoc = { path = "../libbuild_misoc" } [dependencies] -log = { version = "0.3", default-features = false } +log = { version = "0.4", default-features = false } crc = { version = "1.7", default-features = false } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } board = { path = "../libboard" } diff --git a/artiq/firmware/liblogger_artiq/Cargo.toml b/artiq/firmware/liblogger_artiq/Cargo.toml index d9e6e2299..2cf792723 100644 --- a/artiq/firmware/liblogger_artiq/Cargo.toml +++ b/artiq/firmware/liblogger_artiq/Cargo.toml @@ -8,6 +8,6 @@ name = "logger_artiq" path = "lib.rs" [dependencies] -log = { version = "0.3", default-features = false, features = [] } +log = { version = "0.4", default-features = false } log_buffer = { version = "1.0" } board = { path = "../libboard" } diff --git a/artiq/firmware/liblogger_artiq/lib.rs b/artiq/firmware/liblogger_artiq/lib.rs index c51d45b7b..2d7dd531b 100644 --- a/artiq/firmware/liblogger_artiq/lib.rs +++ b/artiq/firmware/liblogger_artiq/lib.rs @@ -7,14 +7,13 @@ extern crate board; use core::cell::{Cell, RefCell}; use core::fmt::Write; -use log::{Log, LogMetadata, LogRecord, LogLevelFilter, MaxLogLevelFilter}; +use log::{Log, LevelFilter}; use log_buffer::LogBuffer; use board::clock; pub struct BufferLogger { buffer: RefCell>, - filter: RefCell>, - uart_filter: Cell + uart_filter: Cell } static mut LOGGER: *const BufferLogger = 0 as *const _; @@ -23,28 +22,18 @@ impl BufferLogger { pub fn new(buffer: &'static mut [u8]) -> BufferLogger { BufferLogger { buffer: RefCell::new(LogBuffer::new(buffer)), - filter: RefCell::new(None), - uart_filter: Cell::new(LogLevelFilter::Info), + uart_filter: Cell::new(LevelFilter::Info), } } pub fn register(&self, f: F) { - // log::set_logger_raw captures a pointer to ourselves, so we must prevent - // ourselves from being moved or dropped after that function is called (and - // before log::shutdown_logger_raw is called). unsafe { - log::set_logger_raw(|max_log_level| { - max_log_level.set(LogLevelFilter::Info); - *self.filter.borrow_mut() = Some(max_log_level); - self as *const Log - }).expect("global logger can only be initialized once"); LOGGER = self; + log::set_logger(&*LOGGER) + .expect("global logger can only be initialized once"); } + log::set_max_level(LevelFilter::Info); f(); - log::shutdown_logger_raw().unwrap(); - unsafe { - LOGGER = 0 as *const _; - } } pub fn with R>(f: F) -> R { @@ -60,34 +49,18 @@ impl BufferLogger { } pub fn extract R>(&self, f: F) -> R { - let old_log_level = self.max_log_level(); - self.set_max_log_level(LogLevelFilter::Off); + let old_log_level = log::max_level(); + log::set_max_level(LevelFilter::Off); let result = f(self.buffer.borrow_mut().extract()); - self.set_max_log_level(old_log_level); + log::set_max_level(old_log_level); result } - pub fn max_log_level(&self) -> LogLevelFilter { - self.filter - .borrow() - .as_ref() - .expect("register the logger before touching maximum log level") - .get() - } - - pub fn set_max_log_level(&self, max_level: LogLevelFilter) { - self.filter - .borrow() - .as_ref() - .expect("register the logger before touching maximum log level") - .set(max_level) - } - - pub fn uart_log_level(&self) -> LogLevelFilter { + pub fn uart_log_level(&self) -> LevelFilter { self.uart_filter.get() } - pub fn set_uart_log_level(&self, max_level: LogLevelFilter) { + pub fn set_uart_log_level(&self, max_level: LevelFilter) { self.uart_filter.set(max_level) } } @@ -96,11 +69,11 @@ impl BufferLogger { unsafe impl Sync for BufferLogger {} impl Log for BufferLogger { - fn enabled(&self, _metadata: &LogMetadata) -> bool { + fn enabled(&self, _metadata: &log::Metadata) -> bool { true } - fn log(&self, record: &LogRecord) { + fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) { let timestamp = clock::get_us(); let seconds = timestamp / 1_000_000; @@ -116,4 +89,7 @@ impl Log for BufferLogger { } } } + + fn flush(&self) { + } } diff --git a/artiq/firmware/libproto/Cargo.toml b/artiq/firmware/libproto/Cargo.toml index 487ae483b..eb805f1eb 100644 --- a/artiq/firmware/libproto/Cargo.toml +++ b/artiq/firmware/libproto/Cargo.toml @@ -10,6 +10,6 @@ path = "lib.rs" [dependencies] byteorder = { version = "1.0", default-features = false } cslice = { version = "0.3" } -log = { version = "0.3", default-features = false, optional = true } +log = { version = "0.4", default-features = false, optional = true } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } dyld = { path = "../libdyld" } diff --git a/artiq/firmware/libproto/mgmt_proto.rs b/artiq/firmware/libproto/mgmt_proto.rs index 123af8915..cb5e08856 100644 --- a/artiq/firmware/libproto/mgmt_proto.rs +++ b/artiq/firmware/libproto/mgmt_proto.rs @@ -2,7 +2,7 @@ use std::vec::Vec; use std::io::{self, Read, Write}; use {ReadExt, WriteExt}; #[cfg(feature = "log")] -use log::LogLevelFilter; +use log; #[derive(Debug)] pub enum Request { @@ -10,9 +10,9 @@ pub enum Request { ClearLog, PullLog, #[cfg(feature = "log")] - SetLogFilter(LogLevelFilter), + SetLogFilter(log::LevelFilter), #[cfg(feature = "log")] - SetUartLogFilter(LogLevelFilter), + SetUartLogFilter(log::LevelFilter), Hotswap(Vec), Reboot, @@ -29,14 +29,14 @@ pub enum Reply<'a> { impl Request { pub fn read_from(reader: &mut Read) -> io::Result { #[cfg(feature = "log")] - fn read_log_level_filter(reader: &mut Read) -> io::Result { + fn read_log_level_filter(reader: &mut Read) -> io::Result { Ok(match reader.read_u8()? { - 0 => LogLevelFilter::Off, - 1 => LogLevelFilter::Error, - 2 => LogLevelFilter::Warn, - 3 => LogLevelFilter::Info, - 4 => LogLevelFilter::Debug, - 5 => LogLevelFilter::Trace, + 0 => log::LevelFilter::Off, + 1 => log::LevelFilter::Error, + 2 => log::LevelFilter::Warn, + 3 => log::LevelFilter::Info, + 4 => log::LevelFilter::Debug, + 5 => log::LevelFilter::Trace, _ => return Err(io::Error::new(io::ErrorKind::InvalidData, "invalid log level")) }) diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index 7057814c1..59dd144c2 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -16,7 +16,7 @@ build_artiq = { path = "../libbuild_artiq" } [dependencies] byteorder = { version = "1.0", default-features = false } cslice = { version = "0.3" } -log = { version = "0.3", default-features = false } +log = { version = "0.4", default-features = false } board = { path = "../libboard", features = ["uart_console", "smoltcp"] } alloc_list = { path = "../liballoc_list" } std_artiq = { path = "../libstd_artiq", features = ["alloc", "io_error_alloc"] } diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index f8f996601..1d6e631f5 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -164,8 +164,7 @@ fn startup_ethernet() { Ok(Ok(log_level_filter)) => { info!("log level set to {} by `log_level` config key", log_level_filter); - logger_artiq::BufferLogger::with(|logger| - logger.set_max_log_level(log_level_filter)); + log::set_max_level(log_level_filter); } _ => info!("log level set to INFO by default") } diff --git a/artiq/firmware/runtime/mgmt.rs b/artiq/firmware/runtime/mgmt.rs index 2933102f5..ee3cbe5fb 100644 --- a/artiq/firmware/runtime/mgmt.rs +++ b/artiq/firmware/runtime/mgmt.rs @@ -1,6 +1,6 @@ use board::boot; use std::io::{self, Read, Write}; -use log::LogLevelFilter; +use log::{self, LevelFilter}; use logger_artiq::BufferLogger; use sched::Io; use sched::{TcpListener, TcpStream}; @@ -44,11 +44,11 @@ fn worker(io: &Io, stream: &mut TcpStream) -> io::Result<()> { io.until(|| BufferLogger::with(|logger| !logger.is_empty()))?; BufferLogger::with(|logger| { - let log_level = logger.max_log_level(); + let log_level = log::max_level(); logger.extract(|log| { stream.write_string(log)?; - if log_level == LogLevelFilter::Trace { + if log_level == LevelFilter::Trace { // Hold exclusive access over the logger until we get positive // acknowledgement; otherwise we get an infinite loop of network // trace messages being transmitted and causing more network @@ -69,8 +69,7 @@ fn worker(io: &Io, stream: &mut TcpStream) -> io::Result<()> { Request::SetLogFilter(level) => { info!("changing log level to {}", level); - BufferLogger::with(|logger| - logger.set_max_log_level(level)); + log::set_max_level(level); Reply::Success.write_to(stream)?; }, diff --git a/artiq/firmware/satman/Cargo.toml b/artiq/firmware/satman/Cargo.toml index 8ca07b053..82db164f9 100644 --- a/artiq/firmware/satman/Cargo.toml +++ b/artiq/firmware/satman/Cargo.toml @@ -14,7 +14,7 @@ build_misoc = { path = "../libbuild_misoc" } build_artiq = { path = "../libbuild_artiq" } [dependencies] -log = { version = "0.3", default-features = false } +log = { version = "0.4", default-features = false } alloc_list = { path = "../liballoc_list" } board = { path = "../libboard", features = ["uart_console"] } board_artiq = { path = "../libboard_artiq" }