logging: Use glib as log backend instead of env_logger.

This makes log output use the same logger as gtk itself and as most other gtk applications
This commit is contained in:
Tom A. Wagner
2022-01-11 12:12:50 +01:00
parent e1fbb0cf49
commit 96182826e4
4 changed files with 20 additions and 22 deletions

18
Cargo.lock generated
View File

@@ -59,7 +59,7 @@ dependencies = [
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"clap", "clap",
"env_logger 0.8.4", "env_logger",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"log", "log",
@@ -210,19 +210,6 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "env_logger"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.2.7" version = "0.2.7"
@@ -415,6 +402,7 @@ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
"libc", "libc",
"log",
"once_cell", "once_cell",
"smallvec", "smallvec",
] ]
@@ -587,7 +575,7 @@ dependencies = [
name = "helvum" name = "helvum"
version = "0.3.2" version = "0.3.2"
dependencies = [ dependencies = [
"env_logger 0.9.0", "glib",
"gtk4", "gtk4",
"log", "log",
"once_cell", "once_cell",

View File

@@ -16,8 +16,8 @@ categories = ["gui", "multimedia"]
[dependencies] [dependencies]
pipewire = "0.4" pipewire = "0.4"
gtk = { version = "0.3", package = "gtk4" } gtk = { version = "0.3", package = "gtk4" }
glib = { version = "0.14", features = ["log"] }
log = "0.4.11" log = "0.4.11"
env_logger = "0.9.0"
once_cell = "1.7.2" once_cell = "1.7.2"

View File

@@ -8,7 +8,7 @@ project(
base_id = 'org.freedesktop.ryuukyu.Helvum' base_id = 'org.freedesktop.ryuukyu.Helvum'
dependency('glib-2.0', version: '>= 2.48') dependency('glib-2.0', version: '>= 2.66')
dependency('gtk4', version: '>= 4.4.0') dependency('gtk4', version: '>= 4.4.0')
dependency('libpipewire-0.3') dependency('libpipewire-0.3')

View File

@@ -21,10 +21,8 @@ mod application;
mod pipewire_connection; mod pipewire_connection;
mod view; mod view;
use gtk::{ use glib::PRIORITY_DEFAULT;
glib::{self, PRIORITY_DEFAULT}, use gtk::prelude::*;
prelude::*,
};
use pipewire::spa::Direction; use pipewire::spa::Direction;
/// Messages sent by the GTK thread to notify the pipewire thread. /// Messages sent by the GTK thread to notify the pipewire thread.
@@ -96,8 +94,20 @@ pub struct PipewireLink {
pub port_to: u32, pub port_to: u32,
} }
static GLIB_LOGGER: glib::GlibLogger = glib::GlibLogger::new(
glib::GlibLoggerFormat::Structured,
glib::GlibLoggerDomain::CrateTarget,
);
fn init_glib_logger() {
log::set_logger(&GLIB_LOGGER).expect("Failed to set logger");
// Glib does not have a "Trace" log level, so only print messages "Debug" or higher priority.
log::set_max_level(log::LevelFilter::Debug);
}
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init(); init_glib_logger();
gtk::init()?; gtk::init()?;
// Aquire main context so that we can attach the gtk channel later. // Aquire main context so that we can attach the gtk channel later.