diff --git a/Cargo.lock b/Cargo.lock index 14cf829..d2b5b5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,6 +668,7 @@ name = "wlroots" version = "0.2.4" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "vsprintf 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "wlroots-dehandle 1.0.0", "wlroots-sys 0.2.1", diff --git a/src/logger.rs b/src/logger.rs deleted file mode 100644 index c6e0407..0000000 --- a/src/logger.rs +++ /dev/null @@ -1,59 +0,0 @@ -use log::{info, max_level, set_boxed_logger, set_max_level, Level, LevelFilter, Metadata, Record}; - -use wlroots::{ - utils::log::{init_logging, WLR_DEBUG, WLR_ERROR, WLR_INFO, WLR_SILENT}, - wlroots_sys::_wlr_log, -}; - -use std::ffi::CString; - -pub fn init(level: LevelFilter) { - init_logging( - match level { - LevelFilter::Off => WLR_SILENT, - LevelFilter::Warn | LevelFilter::Error => WLR_ERROR, - LevelFilter::Info => WLR_INFO, - LevelFilter::Debug | LevelFilter::Trace => WLR_DEBUG, - }, - None, - ); - - let _ = set_boxed_logger(Box::new(Logger)).map(|_| set_max_level(level)); - - info!("Logger initialized!"); -} - -struct Logger; - -impl log::Log for Logger { - fn enabled(&self, metadata: &Metadata) -> bool { - metadata.level() <= max_level() - } - - fn log(&self, record: &Record) { - if self.enabled(record.metadata()) { - let wlr_level = match record.level() { - Level::Warn | Level::Error => WLR_ERROR, - Level::Info => WLR_INFO, - Level::Debug | Level::Trace => WLR_DEBUG, - }; - - let msg = CString::new(if let Some(file) = record.file() { - if let Some(line) = record.line() { - format!("[{}:{}] {}", file, line, record.args()) - } else { - format!("[{}] {}", file, record.args()) - } - } else { - format!("{}", record.args()) - }) - .expect("Could not convert log message to CString"); - - unsafe { - _wlr_log(wlr_level, msg.as_ptr()); - } - } - } - - fn flush(&self) {} -} diff --git a/src/main.rs b/src/main.rs index cfd298d..04a7ce3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,14 @@ mod input; -mod logger; mod output; -use log::{warn, LevelFilter}; +use log::{info, warn, LevelFilter}; use wlroots::{ compositor, cursor::{self, xcursor, Cursor}, input::keyboard, output::layout, + utils::log::Logger, }; struct ExCursor; @@ -50,7 +50,8 @@ impl CompositorState { } fn main() { - logger::init(LevelFilter::Info); + Logger::init(LevelFilter::Info, None); + info!("Logger initialized"); build_compositor().run(); } diff --git a/wlroots-rs b/wlroots-rs index 85e39b8..efae7ee 160000 --- a/wlroots-rs +++ b/wlroots-rs @@ -1 +1 @@ -Subproject commit 85e39b8b723d99ec94bdb219ca9cde56e74b2f12 +Subproject commit efae7ee8f4fb32f553ccd2a5ab05b399efecfa14