Updated wlroots-rs, use their logger

This commit is contained in:
buffet 2019-01-26 19:33:29 +01:00
parent 36e1f03054
commit 45ac1cf781
4 changed files with 6 additions and 63 deletions

1
Cargo.lock generated
View file

@ -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",

View file

@ -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) {}
}

View file

@ -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();
}

@ -1 +1 @@
Subproject commit 85e39b8b723d99ec94bdb219ca9cde56e74b2f12
Subproject commit efae7ee8f4fb32f553ccd2a5ab05b399efecfa14