Updated wlroots-rs, use their logger
This commit is contained in:
parent
36e1f03054
commit
45ac1cf781
4 changed files with 6 additions and 63 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -668,6 +668,7 @@ name = "wlroots"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"vsprintf 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"wlroots-dehandle 1.0.0",
|
"wlroots-dehandle 1.0.0",
|
||||||
"wlroots-sys 0.2.1",
|
"wlroots-sys 0.2.1",
|
||||||
|
|
|
@ -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) {}
|
|
||||||
}
|
|
|
@ -1,14 +1,14 @@
|
||||||
mod input;
|
mod input;
|
||||||
mod logger;
|
|
||||||
mod output;
|
mod output;
|
||||||
|
|
||||||
use log::{warn, LevelFilter};
|
use log::{info, warn, LevelFilter};
|
||||||
|
|
||||||
use wlroots::{
|
use wlroots::{
|
||||||
compositor,
|
compositor,
|
||||||
cursor::{self, xcursor, Cursor},
|
cursor::{self, xcursor, Cursor},
|
||||||
input::keyboard,
|
input::keyboard,
|
||||||
output::layout,
|
output::layout,
|
||||||
|
utils::log::Logger,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExCursor;
|
struct ExCursor;
|
||||||
|
@ -50,7 +50,8 @@ impl CompositorState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
logger::init(LevelFilter::Info);
|
Logger::init(LevelFilter::Info, None);
|
||||||
|
info!("Logger initialized");
|
||||||
|
|
||||||
build_compositor().run();
|
build_compositor().run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 85e39b8b723d99ec94bdb219ca9cde56e74b2f12
|
Subproject commit efae7ee8f4fb32f553ccd2a5ab05b399efecfa14
|
Loading…
Reference in a new issue